retagged by
6,959 views

2 Answers

1 1 vote

in quetion not mentaioned that Array is sorted or not :

I assume it is sorted . it will take log2n for n elements.

So for 64 it takes 6 comparision atmost for any element. Comparision on elements 32, 16, 8, 4, 2,1 

edited by
1 1 vote

we know that recurrance relation for binary search with n elements is:

f(n) = f(n/2) + 2

now, f(64) = f(32) + 2

        f(64) = (f(16) + 2) +2

        f(64) = (f(8) + 4) +2

        f(64) = (f(4) + 6) +2

        f(64) = (f(2) + 8) +2

        f(64) = (f(1) + 10) +2

now, f(1) equals to 2 since two comparisons are required for one number

         this gives f(64) = 14

Position:
Show:

Related questions

5 5 votes
3 answers 3 answers
34.1k
34.1k views
0 0 votes
2 2 answers
1.9k
1.9k views
dhruba asked Jun 5, 2023
1,886 views
Binary search is performed on a sorted array of n elements. The search key is not in the array and falls between the elements at positions m and m+1 (where 1 ≤ m < n). Ho...
4 4 votes
2 answers 2 answers
3.2k
3.2k views
अनुराग पाण्डेय asked Dec 5, 2015
3,152 views
Let you are given an array of nine elements in increasing order. If you want to implement binary search on the given array of element then the number of comparisons per s...
2 2 votes
1 1 answer
202
202 views
GO Classes asked Aug 4
202 views
A sorted table contains $2000$ distinct elements in increasing order. A key is searched using binary search, and it is guaranteed that the key exists in the table.What is...