notes51

notes51 -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 251: Implement a Dictionary Using Binary Search - by Brad Prugar Wednesday, February 15, 2006 15:30 PM Binary Search:  Key and data are same entry.   Example: 2 4 7 8 9 12 17 19 22 25 28 37  :  Find (19) In array: 0 1 2 3 4  5   6  7   8  9  10 11     low = 0                                    high = 11              mid = (low+high)/2 =  5   array(5) = 12.  19 is in the upper half. low = mid + 1 = 6 high = high = 11 mid = (low+high)/2 =  8 array(8) = 22.  19 is in lower half. low = low = 6 high = mid - 1 = 7 mid = (low+high)/2 =  6 array(6) = 17.  19 is in upper half. low = mid + 1 = 7 high = high = 7 mid = (low+high)/2 =  7 array(7) = 19.  19 is in position  7 . We retrieve the data that corresponds to that key and return it.  
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

notes51 -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online