retagged by
5,475 views

2 Answers

1 votes
1 votes

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 votes
1 votes

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

Related questions

0 votes
0 votes
2 answers
3
dhruba asked Jun 5, 2023
1,161 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). ...
11 votes
11 votes
2 answers
4
Shubhanshu asked Jun 5, 2017
11,201 views
The average successful search time taken by binary search on a sorted array of $10$ items?$2.6$$2.7$$2.8$$2.9$Answer is $2.9$My doubt:- But when I am using $log_2n$ for $...