1 / 18

# More on Hash Tables - PowerPoint PPT Presentation

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)

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

## PowerPoint Slideshow about 'More on Hash Tables' - LeeJohn

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

Andy Wang

Data Structures, Algorithms, and Generic Programming

• 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)

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()

Hash Table

Insert()

Hash Table

Insert()

Icarumba!

Hash Table

Linear Probing

Hash Table

Linear Probing

Hash Table

Hash Table

Remove()

Hash Table

Remove()

Hash Table

Hash Table

Lookup()

Hash Table

Insert()

Hash Table

Tricky Case…

Oops…

Hash Table

Insert(…) {

if (Lookup(…) == false) {

// insert

}

}

Remove(…) {

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

// linear search for the entry

}

}

Lookup(…) {

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

// linear search for the entry

}

}