Dale - Computer Science Illuminated 324

Dale - Computer Science Illuminated 324 - 9.5 Binary Search...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 9.5 Binary Search 297 “Fz “z “9z “z “hz “-z “Sz “Tz “z “Pz “ Fz ant cat chicken cow deer dog fish goat horse camel snake Searching for cat BinarySearch(0, 10) BinarySearch(0, 4) BinarySearch(0, 1) BinarySearch(1, 1) Searching for fish BinarySearch(0, 10) BinarySearch(6, 10) BinarySearch(6, 7) Searching for zebra BinarySearch(0, 10) BinarySearch(6, 10) BinarySearch(9, 10) BinarySearch(10, 10) BinarySearch(11, 10) middle: 5 middle: 8 middle: 9 middle: 10 zebra > dog zebra > horse zebra > camel zebra > snake last > first Return: false Figure 9.14 Trace of the binary search middle: 5 middle: 2 middle: 0 middle: 1 cat < dog cat < chicken cat > ant cat = cat Return: true middle: 5 middle: 8 middle: 6 fish > dog fish < horse fish = fish Return: true ...
View Full Document

This note was uploaded on 01/13/2011 for the course CSE 1550 taught by Professor Marianakant during the Fall '10 term at York University.

Ask a homework question - tutors are online