0
0
Data Structures Theoryknowledge~5 mins

Why hash tables enable O(1) lookup in Data Structures Theory - Quick Recap

Choose your learning style9 modes available
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?
AStores data in a linked list
BSorts the data alphabetically
CConverts a key into an array index
DRemoves duplicate data
Why is lookup in a hash table usually O(1)?
ABecause it uses a hash function to find data directly
BBecause it searches the entire array
CBecause it sorts data before searching
DBecause it uses binary search
What is a collision in a hash table?
AWhen the hash function fails
BWhen data is deleted
CWhen the table is empty
DWhen two keys map to the same index
Which method can handle collisions in a hash table?
AChaining
BSorting
CBinary search
DRecursion
If many collisions happen, what happens to lookup time?
AIt becomes faster
BIt becomes slower than O(1)
CIt stays exactly O(1)
DIt becomes zero
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.