# lec5 - MIT OpenCourseWare http:/ocw.mit.edu 6.006...

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

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 .

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

View Full Document
5 Hashing I: Chaining, Hash Functions 6.006 Spring 2008 Lecture 5: Hashing I: Chaining, Hash Functions Lecture Overview Dictionaries and Python Motivation Hash functions Chaining Simple uniform hashing “Good” hash functions Readings CLRS Chapter 11. 1, 11. 2, 11. 3. Dictionary Problem Abstract Data Type (ADT) maintains a set of items, each with a key, subject to insert(item): add item to set delete(item): remove item from set search(key): return item with key if it exists assume items have distinct keys (or that inserting new one clobbers old) balanced BSTs solve in O (lg n ) time per op. (in addition to inexact searches like nextlargest). goal: O (1) time per operation. Python Dictionaries: Items are (key, value) pairs e.g. d = ‘algorithms’: 5, ‘cool’: 42 d.items() [(‘algorithms’, 5),(‘cool’,5)] d[‘cool’] 42 d[42] KeyError ‘cool’ in d True 42 in d False Python set is really dict where items are keys. 1
This is the end of the preview. Sign up to access the rest of the 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 / 7

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

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

View Full Document
Ask a homework question - tutors are online