lecture07 - Introduction to Algorithms...

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

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

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

View Full Document Right Arrow Icon
Introduction to Algorithms Day 11 L7.2 © 2001 by Charles E. Leiserson Symbol-table problem Symbol table T holding n records : key [ x ] record x Other fields containing satellite data Operations on T : I NSERT ( T , x ) D ELETE ( T , x ) S EARCH ( T , k ) How should the data structure T be organized?
Image of page 2
Introduction to Algorithms Day 11 L7.3 © 2001 by Charles E. Leiserson Direct-access table I DEA : Suppose that the set of keys is K {0, 1, …, m –1} , and keys are distinct. Set up an array T [0 . . m –1] : T [ k ] = x if k K and key [ x ] = k , NIL otherwise. Then, operations take Θ (1) time. Problem: The range of keys can be large: 64 -bit numbers (which represent 18,446,744,073,709,551,616 different keys), character strings (even larger!).
Image of page 3

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

View Full Document Right Arrow Icon
Introduction to Algorithms Day 11 L7.4 © 2001 by Charles E. Leiserson Hash functions Solution: Use a hash function h to map the universe U of all keys into {0, 1, …, m –1} : U K k 1 k 2 k 3 k 4 k 5 0 m –1 h ( k 1 ) h ( k 4 ) h ( k 2 ) h ( k 3 ) When a record to be inserted maps to an already occupied slot in T , a collision occurs. T = h ( k 5 )
Image of page 4
Introduction to Algorithms Day 11 L7.5 © 2001 by Charles E. Leiserson Resolving collisions by chaining Records in the same slot are linked into a list. h (49) = h (86) = h (52) = i T 49 86 52 i
Image of page 5

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

View Full Document Right Arrow Icon
Introduction to Algorithms Day 11 L7.6 © 2001 by Charles E. Leiserson Analysis of chaining We make the assumption of simple uniform hashing: Each key k K of keys is equally likely to be hashed to any slot of table T , independent of where other keys are hashed. Let n be the number of keys in the table, and let m be the number of slots. Define the load factor of T to be α = n / m = average number of keys per slot.
Image of page 6
Introduction to Algorithms Day 11 L7.7 © 2001 by Charles E. Leiserson Search cost Expected time to search for a record with a given key = Θ (1 + α ) .
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
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