0
0
DSA Pythonprogramming~5 mins

HashMap Implementation from Scratch in DSA Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a HashMap?
A HashMap is a data structure that stores key-value pairs. It uses a hash function to convert keys into an index where values are stored, allowing fast data retrieval.
Click to reveal answer
beginner
Why do we use a hash function in a HashMap?
A hash function converts a key into an index in an array. This helps quickly find where the value for that key is stored, making lookups fast.
Click to reveal answer
intermediate
What is a collision in a HashMap?
A collision happens when two different keys produce the same index from the hash function. We need a way to handle collisions to store both values correctly.
Click to reveal answer
intermediate
Name one common method to handle collisions in a HashMap.
One common method is chaining, where each array index holds a list of key-value pairs. If multiple keys map to the same index, they are stored in that list.
Click to reveal answer
intermediate
What is the average time complexity for get and put operations in a well-implemented HashMap?
The average time complexity is O(1), meaning it takes constant time to get or put a value, thanks to direct indexing using the hash function.
Click to reveal answer
What does a hash function do in a HashMap?
ASorts the keys alphabetically
BStores the value directly
CConverts a key into an index
DDeletes duplicate keys
What is a collision in a HashMap?
AWhen two keys have the same value
BWhen two keys map to the same index
CWhen a key is missing
DWhen the HashMap is empty
Which method can handle collisions by storing multiple key-value pairs at the same index?
AHashing
BSorting
CBinary Search
DChaining
What is the average time complexity for searching a key in a good HashMap?
AO(1)
BO(log n)
CO(n log n)
DO(n)
In a HashMap, what happens if two keys produce the same index and chaining is not used?
AOne value overwrites the other
BBoth values are stored separately
CThe HashMap resizes automatically
DThe keys are merged
Explain how a HashMap stores and retrieves data using a hash function and handles collisions.
Think about how keys become positions and what happens if two keys want the same spot.
You got /4 concepts.
    Describe the advantages of using a HashMap compared to a simple list for storing key-value pairs.
    Focus on speed and how data is found quickly.
    You got /4 concepts.