Binary search bounds 1

Say you want to search the list [ 0 , 2 , 5 , 5 , 9 , 10 , 11 , 12 , 14 , 15 ] [0,2,5,5,9,10,11,12,14,15] to see if the value 13 is in the list using the binary search algorithm described here .

Which of the following values in the list (not the indices) will never be a value of "first" in the search for 13?


Hint : If you get stuck, try running the code from the binary search page and add a few useful print statements to keep track of the value of the array at index "first."

0 9 10 14

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Karleigh Moore
May 3, 2016

Below is a table describing the search space of the list and the middle element at each iteration of the while loop.

List Middle element
[ 0 , 2 , 5 , 5 , 9 , 10 , 11 , 12 , 14 , 15 ] [0,2,5,5,9,10,11,12,14,15] 9
[ 10 , 11 , 12 , 14 , 15 ] [10,11,12,14,15] 12
[ 14 , 15 ] [14,15] 14

We can see that initially, first was 0 0 , then 10 10 , and finally 14 14 . 9 9 is a middle element at the intial step, but never a value of first.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...