Bonus Lab 5: Hash Tables

Hashing

Given a key, we can use a hash function to compute an index in a hash table.

INDEX = hash_function( KEY )

Searching is extremely fast. Therefore, hashing is suitable for applications like compilers, spell checkers, and security tools.

But it has a limitation: The table size is limited.

Collisions can occur: some keys are mapped to the same location by the hash function.

Critical Issues

1. Design a good hash function

2. Design a method to resolve collisions when they occur

Open Addressing

Separate Chaining


Lab Task

Implement a hash table structure based on the following files:

link2.h: A list class that supports various list operations and is used in the hash table class. You must NOT modify this file.

table2.h: A hash table structure. Finish all parts marked with "===== TO-DO =====":

grader.cpp: A grader program to test your hash table implementation. It should show that you get full marks after you have finished table2.h correctly. Do NOT modify this file. Run the program and show your codes to your TA.

References