Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –

Similar presentations


Presentation on theme: "Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –"— Presentation transcript:

1 Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? – Maintain a sorted array; use binary search – Use sophisticated trees (later in curriculum) – Use an array as a “hash table”

2 Hash Table Implementation Maintain an array of the data to be stored in the data dictionary Need one (or maybe two) hash functions to map the “data” to an index in the array Need a “collision policy” to resolve conflicts when multiple data hash (map) to the same index Insert, Search follow same probe sequence

3 Example Hash Table Data will be strings Array will be size 13 h1(char *) = sum of ASCII values of characters in the string mod table size (13). Collision policy – linear probing – When collision occurs add 1 mod table size to the location of the collision and continue to do that until an empty location is found

4 Hash “Facts” Two “main” kinds of hash tables, called open addressing, and chained hashing Hash tables are very efficient IF table is less than 50% full Linear probing is NOT a good collision policy, BUT, its easy to implement and works well when table is less than 50% full If you’re interested look into double hashing

5 Hash “Facts” Two “main” kinds of hash tables, called open addressing, and chained hashing Hash tables are very efficient IF table is less than 50% full Linear probing is NOT a good collision policy, BUT, its easy to implement and works well when table is less than 50% full If you’re interested look into double hashing

6 Hash Table Effectiveness MethodSuccessful SearchUnsuccessful Search 50%75%90%95%50%75%90%95% Linear1.502.505.5010.502.508.5050.50200.50 Double1.391.852.563.152.004.0010.0020.00 From Data Structure Techniques, p. 154 Thomas A. Standish, 1980


Download ppt "Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –"

Similar presentations


Ads by Google