1 / 6

Hash Tables

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

vida
Download Presentation

Hash Tables

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 From Data Structure Techniques, p. 154 Thomas A. Standish, 1980

More Related