Map Hash Tables and Dictionaries_Part_10

# Map Hash Tables and Dictionaries_Part_10 - then the key is...

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

Last Updated: 06/02/12 10:23 PM CSE 2011 Prof. J. Elder - 46 - Define Step It is faster not to check if the middle element is the key. Simply continue. key 43 3 5 6 13 18 21 21 25 36 43 49 51 53 60 72 74 83 88 91 95 If key mid , then key is in left half. If key > mid , then key is in right half.

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

View Full Document
Last Updated: 06/02/12 10:23 PM CSE 2011 Prof. J. Elder - 47 - Make Progress The size of the list becomes smaller. 3 5 6 13 18 21 21 25 36 43 49 51 53 60 72 74 83 88 91 95 3 5 6 13 18 21 21 25 36 43 49 51 53 60 72 74 83 88 91 95 79 km 75 km
Last Updated: 06/02/12 10:23 PM CSE 2011 Prof. J. Elder - 48 - Exit Condition If the key is contained in the original list, then the key is contained in the sublist. Sublist contains one element. Exit 3 5 6 13 18 21 21 25 36 43 49 51 53 60 72 74 83 88 91 95 0 km • If the key is contained in the original list,

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.

Unformatted text preview: then the key is at this location. key 25 Last Updated: 06/02/12 10:23 PM CSE 2011 Prof. J. Elder - 49 - If key not in original list If the key is contained in the original list, then the key is contained in the sublist. • Loop invariant true, even if the key is not in the list. • If the key is contained in the original list, then the key is at this location. 3 5 6 13 18 21 21 25 36 43 49 51 53 60 72 74 83 88 91 95 key 24 • Conclusion still solves the problem. Simply check this one location for the key. Last Updated: 06/02/12 10:23 PM CSE 2011 Prof. J. Elder - 50 - Running Time The sublist is of size n, n / 2 , n / 4 , n / 8 , … ,1 Each step O(1) time. Total = O(log n) key 25 3 5 6 13 18 21 21 25 36 43 49 51 53 60 72 74 83 88 91 95 If key ≤ mid , then key is in left half. If key > mid , then key is in right half....
View Full Document

## This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

### Page1 / 5

Map Hash Tables and Dictionaries_Part_10 - then the key is...

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

View Full Document
Ask a homework question - tutors are online