{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture08 - Introduction to Algorithms...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 8 Prof. Charles E. Leiserson
Image of page 1

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

View Full Document Right Arrow Icon
Introduction to Algorithms Day 12 L8.2 © 2001 by Charles E. Leiserson 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. 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. An adversary can pick all keys from { k U : h ( k ) = i } for some slot i .
Image of page 2
Introduction to Algorithms Day 12 L8.3 © 2001 by Charles E. Leiserson 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 between x and y is 1/ m if we choose h randomly from H . H { h : h ( x ) = h ( y )} | H | m
Image of page 3

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

View Full Document Right Arrow Icon
Introduction to Algorithms Day 12 L8.4 © 2001 by Charles E. Leiserson 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 .
Image of page 4
Introduction to Algorithms Day 12 L8.5 © 2001 by Charles E. Leiserson Proof of theorem Proof. Let C x be the random variable denoting the total number of collisions of keys in T with x , and let c xy = 1 if h ( x ) = h ( y ) , 0 otherwise. Note: E [ c xy ] = 1/ m and = } { x T y xy x c C .
Image of page 5

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

View Full Document Right Arrow Icon
Introduction to Algorithms Day 12 L8.6 © 2001 by Charles E. Leiserson Proof (continued) = } { ] [ x T y xy x c E C E Take expectation of both sides.
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern