notes51

notes51 - CS251: Wednesday,February15,2006 15:30PM...

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

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.

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

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

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 3

notes51 - CS251: Wednesday,February15,2006 15:30PM...

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

View Full Document
Ask a homework question - tutors are online