1 / 1

Binary Search Example with Labeled Indices

-9. -9. -9. -9. -9. -9. -2. -2. -2. -2. -2. -2. -1. -1. -1. -1. -1. -1. 0. 0. 0. 0. 0. 0. 3. 3. 3. 3. 3. 3. 5. 5. 5. 5. 5. 5. 7. 7. 7. 7. 7. 7. 17. 17. 17. 17. 17. 17. 25. 25. 25. 25. -9. -9. Compare key to middle element….

ulric-baker
Download Presentation

Binary Search Example with Labeled Indices

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. -9 -9 -9 -9 -9 -9 -2 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1 -1 0 0 0 0 0 0 3 3 3 3 3 3 5 5 5 5 5 5 7 7 7 7 7 7 17 17 17 17 17 17 25 25 25 25 -9 -9 Compare key to middle element… It can’t be in the first half; eliminate first half and compare to middle of what remains Can’t be 7 or anything greater; eliminate those elements and compare again Binary Search Example with Labeled Indices blue == high yellow == low green == middle 1 2 3 4 5 6 7 8 9 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.

More Related