Show how binary search algorithm finds 27 in this list 5 6 8
Show how binary search algorithm finds 27 in this list:
5, 6, 8, 12, 15, 21, 25, 31
Solution
Instead of searching the list in sequence, a binary search will start by examining the middle item. If that item is the one we are searching for, we are done. If it is not the correct item, we can use the ordered nature of the list to eliminate half of the remaining items. If the item we are searching for is greater than the middle item, we know that the entire lower half of the list as well as the middle item can be eliminated from further consideration. The item, if it is in the list, must be in the upper half.
binary search starts in the middle and halves the list.
The consecutive choices of sublists of the original list are:
15 21 25 31,25 31,and25.
Since 2725,
the integer25 is not in the list
