More on hash tables
Download
1 / 18

More on Hash Tables - PowerPoint PPT Presentation


  • 354 Views
  • Uploaded on

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)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'More on Hash Tables' - LeeJohn


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
More on hash tables l.jpg

More on Hash Tables

Andy Wang

Data Structures, Algorithms, and Generic Programming


Why hash tables l.jpg
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)


Steps to build a hash table l.jpg
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


Insert l.jpg

Hash(name)

Insert()

Hash Table


Insert5 l.jpg

Hash(name)

Insert()

Hash Table


Insert6 l.jpg

Hash(name)

Insert()

Icarumba!

Hash Table


Linear probing l.jpg

Hash(name)

Linear Probing

Hash Table


Linear probing8 l.jpg

Hash(name)

Linear Probing

Hash Table


Remove l.jpg
Remove()

Hash Table


Remove10 l.jpg

Hash(name)

Remove()

Hash Table


Remove11 l.jpg

Hash(name)

Remove()

Hash Table


Lookup l.jpg
Lookup()

Hash Table


Lookup13 l.jpg

Hash(name)

Lookup()

Hash Table


Insert14 l.jpg

Hash(name)

Insert()

Hash Table


Tricky case l.jpg

Hash(name)

Tricky Case…

Oops…

Hash Table


To handle tricky cases l.jpg
To Handle Tricky Cases

Insert(…) {

if (Lookup(…) == false) {

// insert

}

}

Remove(…) {

if (entry[hash] empty || entry[hash] != key)

// linear search for the entry

}

}


To handle tricky cases17 l.jpg
To Handle Tricky Cases

Lookup(…) {

if (entry[hash] empty || entry[hash] != key)

// linear search for the entry

}

}



ad