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?
The binary search algorithm given in this chapter is nonrecursive. Write and implement a recursive version...
The binary search algorithm given in this chapter is nonrecursive. Write and implement a recursive version of the binary search algorithm. The program should prompt Y / y to continue searching and N / n to discontinue. If an item is found in the list display the following message: x found at position y else: x is not in the list Use the following list of integers when testing your program: 2, 6, 8, 13, 25, 33, 39, 42, 53,...
Complete the following table by specifying algorithm efficiency for : Selection sort, Insertion sort, Binary search,...
Complete the following table by specifying algorithm efficiency for : Selection sort, Insertion sort, Binary search, and Linear search. (Efficiency can be one of : log n, n, n2). List algorithms from the most efficient (fastest) to the least efficient (slowest).    ALGORITHM EFFICENCY 1 most efficient (fastest) 2 3 4 least efficient (slowest)
Select All true answers about linear and binary search 1. The advantage of linear search is...
Select All true answers about linear and binary search 1. The advantage of linear search is that it runs in O(1) space complexity and binary search can only run in O(logn) space complexity 2. The disadvantage of binary search is that it requires the container to be sorted which linear search does not. 3. The advantage of binary search over linear search is that is more efficient O(logn)versus O(n) average/worst case). 4. The advantage of linear search is that it...
a) Design a recursive linear-time algorithm that tests whether a binary tree is a binary search...
a) Design a recursive linear-time algorithm that tests whether a binary tree is a binary search tree. Describe your algorithm in English or with a simple pseudocode program. b) (3 bonus pts.) Extend the algorithm in a) to test whether a binary tree is an AVL tree.
Modify the binary search algorithm implemented in the search method of the HighArray class, to print...
Modify the binary search algorithm implemented in the search method of the HighArray class, to print a trace showing for each iteration of the search, the upper and lower limits of the search and the middle item selected in the binary split. The output might look something like this: Pass 1 left=0 right=9 pivot=4 Pass 2 left=0 right =3 pivot =1 Pass 3 left=2 right =3 pivot =2
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
Python: Write a program that performs a logarithmic search on an ordered list of 1000 elements....
Python: Write a program that performs a logarithmic search on an ordered list of 1000 elements. The search on the list should be on a randomly generated number between 1-1000.
Python: Write a program that performs a sequential search on an ordered list of 1000 elements....
Python: Write a program that performs a sequential search on an ordered list of 1000 elements. The search on the list should be on a randomly generated number between 1-1000.