module05 - Module 5 Hashing CS 240 Data Structures and Data...

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

View Full Document Right Arrow Icon
Module 5: Hashing CS 240 - Data Structures and Data Management Arne Storjohann Based on lecture notes by R. Dorrigiv and D. Roche School of Computer Science, University of Waterloo Fall 2010 Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 1 / 27
Image of page 1

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

View Full Document Right Arrow Icon
Lower bound for search The fastest implementations of the dictionary ADT require Θ(log n ) time to search a dictionary containing n items. Is this the best possible? Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 2 / 27
Image of page 2
Lower bound for search The fastest implementations of the dictionary ADT require Θ(log n ) time to search a dictionary containing n items. Is this the best possible? Theorem : In the comparison model (on the keys), Ω(log n ) comparisons are required to search a size- n dictionary. Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 2 / 27
Image of page 3

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

View Full Document Right Arrow Icon
Lower bound for search The fastest implementations of the dictionary ADT require Θ(log n ) time to search a dictionary containing n items. Is this the best possible? Theorem : In the comparison model (on the keys), Ω(log n ) comparisons are required to search a size- n dictionary. Proof : Similar to lower bound for sorting. Any algorithm defines a binary decision tree with comparisons at the nodes and actions at the leaves. There are at least n + 1 different actions (return an item, or “not found”). So there are Ω( n ) leaves, and therefore the height is Ω(log n ). Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 2 / 27
Image of page 4
Direct Addressing Requirement : For a given M N , every key k is an integer with 0 k < M . Data structure : An array of values A with size M search ( k ) : Check whether A [ k ] is empty insert ( k , v ) : A [ k ] v delete ( k ) : A [ k ] empty Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 3 / 27
Image of page 5

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

View Full Document Right Arrow Icon
Direct Addressing Requirement : For a given M N , every key k is an integer with 0 k < M . Data structure : An array of values A with size M search ( k ) : Check whether A [ k ] is empty insert ( k , v ) : A [ k ] v delete ( k ) : A [ k ] empty Each operation is Θ(1) . Total storage is Θ( M ). What sorting algorithm does this remind you of? Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 3 / 27
Image of page 6
Direct Addressing Requirement : For a given M N , every key k is an integer with 0 k < M . Data structure : An array of values A with size M search ( k ) : Check whether A [ k ] is empty insert ( k , v ) : A [ k ] v delete ( k ) : A [ k ] empty Each operation is Θ(1) . Total storage is Θ( M ). What sorting algorithm does this remind you of? Counting Sort Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 3 / 27
Image of page 7

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

View Full Document Right Arrow Icon
Hashing Direct addressing isn’t possible if keys are not integers. And the storage is very wasteful if n M . Say keys come from some universe U . Use a hash function h : U → { 0 , 1 , . . . , M - 1 } . Generally, h is not injective, so many keys can map to the same integer. Arne Storjohann (CS, UW) CS240 - Module 5 Fall 2010 4 / 27
Image of page 8
Hashing Direct addressing isn’t possible if keys are not integers.
Image of page 9

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

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