1 / 18

More on Hash Tables

More on Hash Tables. Andy Wang Data Structures, Algorithms, and Generic Programming. Why Hash Tables?. Arguments Linear search is simple Hash table does not save that much time Counter arguments What if the data volume is high? (internet routers)

LeeJohn
Download Presentation

More on 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. More on Hash Tables Andy Wang Data Structures, Algorithms, and Generic Programming

  2. Why Hash Tables? • Arguments • Linear search is simple • Hash table does not save that much time • Counter arguments • What if the data volume is high? (internet routers) • What if the data set if large? (yellow page)

  3. Steps to Build a Hash Table 1. Build a table to support basic operations • Insert • Lookup • Remove 2. Use a hash function to determine the table entry 3. Add mechanisms to handle collisions

  4. Hash(name) Insert() Hash Table

  5. Hash(name) Insert() Hash Table

  6. Hash(name) Insert() Icarumba! Hash Table

  7. Hash(name) Linear Probing Hash Table

  8. Hash(name) Linear Probing Hash Table

  9. Remove() Hash Table

  10. Hash(name) Remove() Hash Table

  11. Hash(name) Remove() Hash Table

  12. Lookup() Hash Table

  13. Hash(name) Lookup() Hash Table

  14. Hash(name) Insert() Hash Table

  15. Hash(name) Tricky Case… Oops… Hash Table

  16. To Handle Tricky Cases Insert(…) { if (Lookup(…) == false) { // insert } } Remove(…) { if (entry[hash] empty || entry[hash] != key) // linear search for the entry } }

  17. To Handle Tricky Cases Lookup(…) { if (entry[hash] empty || entry[hash] != key) // linear search for the entry } }

  18. How can we make it more efficient?

More Related