edited by
528 views
1 votes
1 votes

The program written for binary search, calculates the midpoint of the span as $\text{mid : =(Low+High)/2}$. The program works well if the number of elements in the list is small (about $32,000$) but it behaves abnormally when the number of elements is large. This can be avoided by performing the calculation as:

  1. $\text{mid :=(High-Low)/2+Low}$
  2. $\text{mid :=(High-Low+1)/2}$
  3. $\text{mid :=(High-Low)/2}$
  4. $\text{mid :=(High+Low)/2}$
edited by

2 Answers

1 votes
1 votes
Eliminate option D due to it's same as the defective one.

considering Low index $=10,$ high index $= 15$

option B gives, mid index $= 3$ which is not even in the sub array index.

option C gives, mid index $= 2$ which is not even in the sub array index.

Option A is correct.
edited by
0 votes
0 votes

Option B  and Option C do not match    mid  =  (Low +High)/2

Option D is same as the defective one  mention in the question  mid = (low +High)/2

so Eliminate option B , C  and  D

now , lets solve 

mid = ( High – Low ) / 2 + Low

mid  = (High – Low + 2Low ) /2

mid = ( High + Low ) / 2     →  which is equivalent to     mid = ( Low + High ) / 2  given in the question 

so after solving we got  option ( A) is correct answer .

 

Answer:

Related questions

3 votes
3 votes
4 answers
1
2 votes
2 votes
2 answers
2
gatecse asked Dec 9, 2020
749 views
Number of letter repeated in the given word $’MEASUREMENTS’$ are indicated in front of each alternative. Identify the correct alternative.$M_2E_2A_2S_2U_1R_1N_1T_1$$M...
2 votes
2 votes
1 answer
3
gatecse asked Dec 9, 2020
723 views
If $09/12/2001(DD/MM/YYYY)$ happens to be Sunday, then $09/12/1971$ would have been a:WednesdayTuesdaySaturdayThursday
2 votes
2 votes
2 answers
4
gatecse asked Dec 9, 2020
817 views
If a cube with length, height and width equal to $10\; cm$, is reduced to a smaller cube of height, length and width of $9\; cm$ then reduction in volume is :$172\;cm^3$$...