Recall & Review
beginner
What is a hash table?
A hash table is a data structure that stores data in an array format, using a special function called a hash function to compute an index where the data is stored or retrieved.
Click to reveal answer
beginner
What role does the hash function play in a hash table?
The hash function converts a key into an index in the array, allowing quick access to the data stored at that position.
Click to reveal answer
intermediate
Why do hash tables provide O(1) lookup time on average?
Because the hash function directly computes the index where the data is stored, the lookup does not require searching through the entire data set, making it very fast and close to constant time.
Click to reveal answer
intermediate
What is a collision in a hash table?
A collision happens when two different keys produce the same index from the hash function. Hash tables use methods like chaining or open addressing to handle collisions.
Click to reveal answer
intermediate
How do collisions affect the lookup time in a hash table?
Collisions can slow down lookup time because multiple items share the same index, requiring extra steps to find the correct item. However, with good hash functions and collision handling, lookup remains close to O(1).
Click to reveal answer
What does a hash function do in a hash table?
✗ Incorrect
A hash function converts a key into an index where the data is stored or retrieved.
Why is lookup in a hash table usually O(1)?
✗ Incorrect
The hash function computes the exact index, so lookup is direct and fast.
What is a collision in a hash table?
✗ Incorrect
A collision occurs when different keys produce the same index.
Which method can handle collisions in a hash table?
✗ Incorrect
Chaining stores collided items in a list at the same index.
If many collisions happen, what happens to lookup time?
✗ Incorrect
More collisions mean more items to check, slowing down lookup.
Explain how a hash table uses a hash function to achieve fast lookup.
Think about how you find a book quickly in a library using a catalog number.
You got /3 concepts.
Describe what a collision is in a hash table and how it can affect performance.
Imagine two people trying to sit in the same chair at the same time.
You got /3 concepts.