lec8 - Introduction to Algorithms 6.046J/18.401J LECTURE 8...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J L ECTURE 8 Hashing II Universal hashing Universality theorem Constructing a set of universal hash functions Perfect hashing Prof. Charles E. Leiserson October 5, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.1
Background image of page 1

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

View Full DocumentRight Arrow Icon
A weakness of hashing Problem: For any hash function h , a set of keys exists that can cause the average access time of a hash table to skyrocket. An adversary can pick all keys from { k U : h ( k ) = i } for some slot i . I DEA : Choose the hash function at random, independently of the keys. Even if an adversary can see your code, he or she cannot find a bad set of keys, since he or she doesn’t know exactly which hash function will be chosen. October 5, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.2
Background image of page 2
Universal hashing Definition. Let U be a universe of keys, and let H be a finite collection of hash functions, each mapping U to {0, 1, …, m –1} . We say H is universal if for all x , y U , where x y , we have |{ h H : h ( x ) = h ( y )}| = | H |/ m . That is, the chance of a collision { h : h ( x ) = H h ( y )} between x and y is 1/ m if we choose h | H | randomly from H . m October 5, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Universality is good Theorem. Let h be a hash function chosen (uniformly) at random from a universal set H of hash functions. Suppose h is used to hash n arbitrary keys into the m slots of a table T . Then, for a given key x , we have E [#collisions with x ] < n / m . October 5, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L7.4
Background image of page 4
Proof. Let C x be the random variable denoting the total number of collisions of keys in T with x , and let 1 if h ( x ) = h ( y ) , c = xy 0 otherwise. Note:
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

lec8 - Introduction to Algorithms 6.046J/18.401J LECTURE 8...

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

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