module05

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

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

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

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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
Hashing Direct addressing isn’t possible if keys are not integers.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern