recitation05

recitation05 - MIT OpenCourseWare http://ocw.mit.edu 6.006...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 worst-case, 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 (worst-case) • comparison model (an order relation on keys is sufFcient) • pwns in real-time • Hashing • O(1) / op avg-case • no guarantees for worst-case -- 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.

Page1 / 27

recitation05 - MIT OpenCourseWare http://ocw.mit.edu 6.006...

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

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