Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Search Example with Labeled Indices

Similar presentations


Presentation on theme: "Binary Search Example with Labeled Indices"— Presentation transcript:

1 Binary Search Example with Labeled Indices
yellow == low green == middle blue == high -9 -2 -1 3 5 7 17 25 -9 -2 -1 3 5 7 17 25 Compare key to middle element… -9 -2 -1 3 5 7 17 25 It can’t be in the first half; eliminate first half and compare to middle of what remains -9 -2 -1 3 5 7 17 25 -9 -2 -1 3 5 7 17 Can’t be 7 or anything greater; eliminate those elements and compare again -9 -2 -1 3 5 7 17 5 is now the only thing remaining in the array. It is thus also the middle. Since the middle equals the key, we’ve successfully found our key.


Download ppt "Binary Search Example with Labeled Indices"

Similar presentations


Ads by Google