This preview shows pages 1–10. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms . 6.006 Recitation Build 2008.10 Coming Up Next... • Hashing in theory and in Python • Bad hash functions • Mutable dictionary keys • Hashes for basic data types in Python Why Hashing • Useless from a theoretical standpoint • O(N) / op worstcase, not Ft for proofs • Used everywhere (dictionaries, indices) • O(1) / op is smokin’ hot / fast • Simple  small constant factor • Relies on black magic Hashing pwns BSTs? • BSTs • O(lg(N)) / op • guaranteed upper bound (worstcase) • comparison model (an order relation on keys is sufFcient) • pwns in realtime • Hashing • O(1) / op avgcase • no guarantees for worstcase  O(N) • intimate knowledge of keys (via magic inside the hash function) • rocks for most cases Real Life Hashing I • Application: Keeping library cards • 4x6” card for each book • Fling by the 1st letter of the book title • e.g.“Differential Equations” goes to D • no sorting asides from mechanism above Real Life Hashing II • fling is uncool, let’s think of bucketing • 26 buckets, labeled ‘A’  ‘Z’ • Books are bucketed by 1st letter in title • Time to Fnd a book ~ bucket size Real Life Hashing III • What sucks in the scheme above? • Common preFxes • “The ...”,“Introduction to...” • Uneven distribution • Many words start with E • ¡ew words start with X Real Life Hashing IV • Solutions to issues above?...
View
Full
Document
This note was uploaded on 09/24/2010 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.
 Spring '08
 ErikDemaine
 Algorithms

Click to edit the document details