Hashing Exercises
Complete the following individually, then turn to a neighbor to confirm your answers.
- Hash Table Basics
- What is the underlying data structure for a hash table?
- A _______ determines the location to start to look in a hash table for a key.
- What would the hash function look like if a string is used as the key?
- Explain the pattern displayed when adding in each character using string folding: StringFoldingDemo.java
- What are the requirements for a good hash function?
- A hash function should be careful not to just use the high- or low-order bits of the key value. What are the high-order and low-order bits?
- Insert the following numbers into a hash table of size 7 and draw the resulting hash table:
- Calculate the load factor α for the previous example.
- Hashing: Handling Collisions
- For each of the following strategies:
- Separate chaining
- Linear probing (f(i) = i, or p(K,i) = i)
- Quadratic probing (f(i) = i2, or p(K,i) = i2)
- Double hashing (f(i) = i * h2(x), or p(K,i) = i * h2(K)) and h2(x) = R - (x % R) (where R is the prime number just smaller than tableSize M)
Do the following:
- Given a hash table with 7 entries, draw the hash table and its contents after inserting the following numbers: 7, 11, 71, 42, 13, 49
- Describe the major steps for:
- Inserting an item
- Retrieving an item
- Deleting an item
- Displaying all items in the hash table
- Calculate the load factor α
Rehashing
- What is rehashing?
- What are the major steps of rehashing?
- Why do we rehash?
- When do we rehash?
Last Modified: