Download presentation
Presentation is loading. Please wait.
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.