This preview shows pages 1–9. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 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 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 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 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 Hashing Direct addressing isnt possible if keys are not integers. And the storage is very wasteful if n M ....
View
Full
Document
This note was uploaded on 01/14/2012 for the course CS 246 taught by Professor Wormer during the Winter '08 term at Waterloo.
 Winter '08
 WORMER
 Data Management, Data Structures

Click to edit the document details