Collision handling is a method used to resolve situations when two different keys hash to the same index in a hash table.
Click to reveal answer
beginner
Explain the chaining method for collision handling.
Chaining handles collisions by storing all elements that hash to the same index in a linked list or chain at that index.
Click to reveal answer
intermediate
Why is chaining considered a simple and effective collision handling technique?
Because it allows multiple elements to be stored at the same index without overwriting, and it is easy to implement using linked lists.
Click to reveal answer
intermediate
What happens when many keys collide and are stored in the same chain?
The chain becomes longer, which can slow down search, insertion, and deletion operations because they require traversing the list.
Click to reveal answer
advanced
How can the performance of chaining be improved in a hash table?
By keeping the load factor low through resizing the table or using a good hash function to distribute keys evenly.
Click to reveal answer
What does chaining use to handle collisions in a hash table?
ALinked lists at each index
BOpen addressing
CRehashing
DBinary search trees
✗ Incorrect
Chaining uses linked lists (or similar structures) at each index to store multiple elements that hash to the same slot.
What is a disadvantage of chaining when many keys collide?
AHash function stops working
BThe hash table size decreases
CKeys get lost
DChains become long, slowing down operations
✗ Incorrect
Long chains mean more elements to check during search, insertion, or deletion, which slows down these operations.
Which of the following is NOT a benefit of chaining?
ARequires no extra memory
BHandles unlimited collisions gracefully
CAllows easy insertion
DSimple to implement
✗ Incorrect
Chaining requires extra memory for linked lists, so it does need additional memory beyond the array.
How can chaining performance be improved?
ABy increasing the load factor
BBy using a poor hash function
CBy resizing the hash table to reduce load
DBy storing all keys in one chain
✗ Incorrect
Resizing the table reduces the load factor, which shortens chains and improves performance.
In chaining, what data structure is commonly used to store collided elements?
AArray
BLinked list
CStack
DQueue
✗ Incorrect
Linked lists are commonly used because they allow easy insertion and traversal of collided elements.
Describe how collision handling by chaining works in a hash table.
Think about what happens when two keys hash to the same place.
You got /4 concepts.
Explain the advantages and disadvantages of using chaining for collision handling.
Consider both ease of use and performance impact.
You got /4 concepts.
Practice
(1/5)
1. What is the main idea behind collision handling by chaining in hash tables?
easy
A. Use a second hash function to find a new index
B. Overwrite the existing item when a collision occurs
C. Resize the hash table immediately after a collision
D. Store collided items in a linked list at the same index
Solution
Step 1: Understand collision in hash tables
When two keys hash to the same index, a collision occurs.
Step 2: Explain chaining method
Chaining stores all collided items in a linked list at that index, preserving all entries.
Final Answer:
Store collided items in a linked list at the same index -> Option D
Quick Check:
Chaining = linked list at index [OK]
Hint: Chaining means linked lists hold collisions at one spot [OK]
Common Mistakes:
Thinking collisions overwrite existing data
Confusing chaining with open addressing
Assuming resizing happens immediately on collision
2. Which of the following is the correct way to represent chaining in a hash table?
easy
A. Each index holds a single value only
B. Each index holds a linked list of values
C. Each index holds a separate hash table
D. Each index holds a fixed-size array of values
Solution
Step 1: Recall chaining structure
Chaining uses linked lists to store multiple items at one index.
Step 2: Match options to chaining
Only Each index holds a linked list of values describes linked lists at each index, which is chaining.
Final Answer:
Each index holds a linked list of values -> Option B
Quick Check:
Chaining = linked list per index [OK]
Hint: Chaining means linked lists at each hash index [OK]
Common Mistakes:
Choosing single value per index (no chaining)
Confusing chaining with nested hash tables
Thinking arrays are used instead of lists
3. Consider a hash table using chaining with 5 buckets. The hash function is h(key) = key % 5. Insert keys 7, 12, 17, 22. What does the bucket at index 2 contain?
medium
A. [7, 12, 17, 22]
B. [7, 17]
C. [12, 22]
D. [2]
Solution
Step 1: Calculate hash for each key
7 % 5 = 2, 12 % 5 = 2, 17 % 5 = 2, 22 % 5 = 2. All keys map to index 2.
Step 2: List keys in bucket 2
Bucket 2 contains keys 7, 12, 17, 22.
Step 3: Verify which keys actually hash to 2
7 % 5 = 2, 12 % 5 = 2, 17 % 5 = 2, 22 % 5 = 2. All keys map to index 2.
Step 4: Check options carefully
[7, 17] lists [7, 17], but keys 12 and 22 also hash to 2, so [7, 17] is incomplete. [7, 12, 17, 22] lists all keys, which is correct.
Final Answer:
[7, 12, 17, 22] -> Option A
Quick Check:
All keys mod 5 = 2 [OK]
Hint: Apply mod function to keys to find bucket [OK]
Common Mistakes:
Miscomputing modulo operation
Assuming keys distribute to different buckets
Confusing bucket index with key values
4. A hash table uses chaining but the linked list at one index is not updated correctly after insertion. What is the likely error?
medium
A. The new node is not linked to the existing list
B. The hash function returns different values for same key
C. The table size is too small
D. The keys are not unique
Solution
Step 1: Understand chaining insertion
When inserting, the new node must link to the existing list at that index.
Step 2: Identify error from symptoms
If the list is not updated, likely the new node was not linked properly.
Final Answer:
The new node is not linked to the existing list -> Option A
Quick Check:
Missing link causes list update failure [OK]
Hint: Check if new node links to list head [OK]
Common Mistakes:
Blaming hash function for insertion errors
Thinking table size causes linking issues
Confusing key uniqueness with chaining errors
5. You have a hash table with chaining. If many keys hash to the same index, what is the best way to improve performance?
hard
A. Ignore collisions and overwrite old keys
B. Use a linked list with more nodes at that index
C. Increase the table size and rehash all keys
D. Store all keys in a single bucket
Solution
Step 1: Understand impact of many collisions
Many keys in one bucket slow down search because linked list grows long.
Step 2: Improve performance by resizing
Increasing table size reduces collisions by spreading keys across more buckets.
Step 3: Rehash keys after resizing
Rehashing redistributes keys according to new table size for better balance.
Final Answer:
Increase the table size and rehash all keys -> Option C
Quick Check:
Resize + rehash reduces collisions [OK]
Hint: Resize table and rehash keys to reduce collisions [OK]
Common Mistakes:
Adding more nodes without resizing
Overwriting keys loses data
Putting all keys in one bucket defeats hashing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.