# Binary Search Algorithm-Multiple Choice Question

Question

Consider the following Binary Search Algorithm

upper = length - 1;

lower = 1;

while (upper >= lower)

{ mid_pt = (upper + lower) / 2;

if (data[mid_pt] < target) ; comparison A

{ lower = mid_pt + 1; }

else if (data[mid_pt] == target) ; comparison B

{ return mid_pt; }

else { upper = mid_pt – 1;}

}

Give the values for lower, upper and mid-pt for each iteration of the while loop and state how many times will the two comparisons A and B be executed using this algorithm to find the value 77 in the following array? You may not need to complete all the rows.

 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] 14 27 29 38 42 55 57 61 64 69 77 79 84
 Lower Upper Mid-pt - - - - - - - - - - - - - - -

Comparison A executed ------ times & Comparison B executed ------- times.

• Rasha

this is a very good website

• maani

I have 50 questions for the same test your page is showing only 28

• joeanne

• joeanne

hi can anyone help or guide me to my assignments. thanks

• Monik

• Cristina

This solution is perfect ...thanks

• Janete

Hello Allison,I love the 2nd image that you did! I also, had never heard of SumoPaint, is something that I will have to exolpre a bit! I understand completely the 52 (or so) youtube videos that you probably watched. Sometimes they have what you want, sometimes they don't! However, it is always satisfying when you are able to produce something that you have taught yourself. Great job!Debra 0 likes

• Sandeep

Perfect bank of solution.

• Oxana

great !

• Paul Brandon-Fritzius

thanks for the quick response. the solution looks good. :)

• tina Johnson

thnx for the answer. it was perfect. just the way i wanted it.

• Giuseppe

works fine.