edited by
2,343 views
3 votes
3 votes

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 successful search on an average will be:


Average is 2.78,

should I answer this question with or without rounding off 2.78, as number of comparisons is an integral value?

 

2 Answers

3 votes
3 votes
Let's take an example :-

$1,2,3,4,5,6,7,8,9$

It take $1$ comparison to search for $5$.

It takes $2$ comparisons to search for $2 \ and \ 7$.

It takes $3$ comparisons to search for $2,4,6 \ and \ 8$.

And it takes $4$ comparisons for $1,9$.

Thus average =$\frac{1+4*3+2*2+4*2}{9}=\frac{25}{9}=2.7777 = 2.78$
Answer:

Related questions

2 votes
2 votes
2 answers
2
Rohan Mundhey asked Nov 9, 2016
5,475 views
How many comparisons are needed for a binary search in a set of 64 elements?
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). ...
2 votes
2 votes
1 answer
4
shivani2010 asked Jun 12, 2016
1,149 views
Binary search algorithm employs the strategy ofDivide and Conquer techniqueDynamic ProgrammingBranch & Bound techniqueGreedy Strategy