Separate chaining: basic algorithms
-
When inserting a key K in a table with hash function H(K)
1. Set indx = H(K)
2. Insert key in linked list headed at indx. (Search the list first to avoid duplicates.)
-
When searching for a key K in a table with hash function H(K)
1. Set indx = H(K)
2. Search for key in linked list headed at indx, using linear search.
-
When deleting a key K in a table with hash function H(K)
1. Set indx = H(K)
2. Delete key in linked list headed at indx
-
Advantages: average case performance stays good as number of entries approaches
and even exceeds M; delete is easier to implement than with open addressing
-
Disadvantages: requires dynamic data, requires storage for pointers in addition to data, can have poor locality which causes poor caching performance
CONTENTS PREVIOUS NEXT