in Algorithms edited by
2,004 views
3 votes
3 votes

The average successful search time taken by binary search on a sorted array of 5 CONSECUTIVE integers starting with 1?

My Answer is - 2.2

Kindly tell me is it correct or not?

NOTE: I have edited the question and changes are shown in highlighted text.

in Algorithms edited by
by
2.0k views

4 Comments

1
1

@ rahul sharma 5 Yes, similar question, but may you help me with mine with 5 elements?

0
0
0
0

1 Answer

3 votes
3 votes
Best answer

There are 5 consecutive numbers starting with 1, so the numbers are

1,2,3,4,5 in the exact same order.

Suppose we use binary search to search for '1'.

then there will be three comparisons to find the number 1.

  1. First we will check the middle element i.e, 3
  2. Then we will check the left sub-array's middle element i.e, 2
  3. And we continue in this manner till we find 1

So we will need 3 comparisons to find 1.

Likewise  we will need,

2 comparisons to find 2,

1 comparison to find 3,

2 comparisons to find 4,

3 comparisons to find 5.

Hence totally we need  $3+2+1+2+3 = 11$ comparisons.

The Average no. of Comparisons will be $11/5 = 2.2$

So the answer is $2.2$

selected by

1 comment

Thank you, Sir!
0
0
Answer:

Related questions