Question

The maximum number of searches required by the binary search algorithm to search an ordered list...

The maximum number of searches required by the binary search algorithm to search an ordered list of n items, where n is a power of 2, what is the time complexity?

Homework Answers

Answer #1

Let us consider n=1000..

and in worst case scenario we are searching for the element stored in the oth index then it will search for 10 times to reach it.

As 1000/2=500.

500/2=250.

250/2=125.

125/2=62.

62/2=31.

31/2=15.

15/2=7.

7/2=3.

3/2=1.

1/2=0.

There by if there are n elements exists in a sorted array,then maximum number of comparisons may require is log2n.

Explanation:

Binary Search Algorithm is known as half interval search or the logarithmic search which finds the position of the target value within a sorted array only.

It starts with the middle element of the array and if the target value matches with the middle element then it is the best case possible in O(1).

If it does not match with the current middle value then it compares with the value stored in the middle index.

If the value in the middle index is greater than the target value then the search goes to the right side of the array and if the value in the middle index is lesser than the target value then the search goes to the left side of the array.

Algorithm

1. Set L to 0 R to n-1

2. If L>R,then search terminates as unsuccesful.

3.Set m ( the position of the middle element) to the floor(largest prev integer) to (L+R)/2

4. If target=Am ,the search is done.

5. If target>Am ,set L to m+1 and go to step 2

6. If target<Am set L to m-1 and go to step 2

Time Complexity

T(n)=T(n/2)+1 if n>1

T(n)=1 if n=1

There by T(n)=O(log2n)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
what is the largest number of entries that are interrogated if the binary search algorithm is...
what is the largest number of entries that are interrogated if the binary search algorithm is applied to a list of 4000 names? how does this compare to the sequencial search?
Explain Binary Search Algorithm to search for V = 75, using the data given below                ...
Explain Binary Search Algorithm to search for V = 75, using the data given below                 5, 10, 25, 35, 45, 50, 60, 70, 75, 80, 85    How many searches will be needed?
State True or False. i) Binary search is used for searching in a sorted array. AND...
State True or False. i) Binary search is used for searching in a sorted array. AND ii) The time complexity of binary search is O(log n). A) True, False B) False, True C) False, False D) True, True Explain
Given the list of values below, create a Binary Search Tree for the list, Use the...
Given the list of values below, create a Binary Search Tree for the list, Use the first value in the list as the root of the tree, add the nodes to BST in the order they appear in the list.[50, 44, 82, 39, 35, 98, 87, 100, 74, 23, 34, 14, 94] What is the minimum height of a Binary Tree that contains 24nodes? What is the minimum height of a Binary Tree that contains 64nodes? What is the minimum...
Consider a binary search tree where each tree node v has a field v.sum which stores...
Consider a binary search tree where each tree node v has a field v.sum which stores the sum of all the keys in the subtree rooted at v. We wish to add an operation SumLE(K) to this binary search tree which returns the sum of all the keys in the tree whose values are less than or equal to K. (a) Describe an algorithm, SumLE(K), which returns the sum of all the keys in the tree whose values are less...
In this programming exercise you will create an algorithm for solving the following version of the...
In this programming exercise you will create an algorithm for solving the following version of the m Smallest Numbers problem.   Instead of just returning the m smallest values as in homework 1, you want to return a list of the positions where the m smallest values are located without changing the original array. Your algorithm should meet the following specifications: mSmallest( L[1..n], m ) Pre: L is a list of distinct integer values. n is the number of elements in...
Pseudocode an algorithm that takes as input a list of n integers and finds the number...
Pseudocode an algorithm that takes as input a list of n integers and finds the number of even integers in the list.
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
This is artifical Intelligent class computer 1.List the typical search algorithms in each group. 2.For each...
This is artifical Intelligent class computer 1.List the typical search algorithms in each group. 2.For each typical search algorithm, list its properties and characteristics. 3.What is the "Perception-Action Problem"?
‏What is the output of the Euler tour in the normal binary search tree if the...
‏What is the output of the Euler tour in the normal binary search tree if the key insert order is 5 , 2 , 8 , 5 , 9 , 5 , 1 , 3 , 4 , 2 , 8 ? All keys equal to the node should be the right subtree of that node. ____________________________________________________________ ‏Construct the binary max - heap for the keys given below. Once all the keys are inserted, perform the remove maximum operation, and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT