Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
HashingEasy
Q1. What is a collision in hashing?
- A.When a key is not found in the table
- B.When two keys hash to the same index✓ Correct
- C.When the hash table is completely full
- D.When the hash function fails to compute
Explanation
A collision occurs when two different keys produce the same hash value (index) in the hash table.
Report an error in this question
HashingEasy
Q2. What is a hash table?
- A.A binary tree data structure
- B.A sorted array structure
- C.A type of linked list structure
- D.A key-value store using hash function✓ Correct
Explanation
A hash table (hash map) stores key-value pairs and uses a hash function to compute an index for quick insertion, deletion, and lookup.
Report an error in this question
HashingEasy
Q3. What is the worst-case time complexity of hash table lookup?
- A.O(1)
- B.O(n^2)
- C.O(log n)
- D.O(n)✓ Correct
Explanation
In the worst case, all keys hash to the same index, creating a single linked list (chaining) that must be traversed, giving O(n).
Report an error in this question
HashingEasy
Q4. What is the average time complexity of lookup in a hash table?
- A.O(n)
- B.O(log n)
- C.O(n^2)
- D.O(1)✓ Correct
Explanation
With a good hash function and low load factor, hash table lookups take O(1) average time.
Report an error in this question
HashingMedium
Q5. What is linear probing?
- A.Using a linear hash function for keys
- B.Checking next consecutive slots on collision✓ Correct
- C.Using a linked list for collision handling
- D.Probing with a linear mathematical equation
Explanation
Linear probing resolves collisions by sequentially checking the next slots (index + 1, index + 2, ...) until an empty slot is found.
Report an error in this question
HashingEasy
Q6. What is a hash function?
- A.A function that encrypts all data
- B.A function that compresses file data
- C.A function that sorts data elements
- D.A function that maps data to fixed-size value✓ Correct
Explanation
A hash function maps input data of arbitrary size to a fixed-size output value, used to determine the index in a hash table.
Report an error in this question
HashingEasy
Q7. Which of the following is a simple hash function for integers?
- A.h(k) = k + table_size
- B.h(k) = k × table_size
- C.h(k) = k / table_size
- D.h(k) = k mod table_size✓ Correct
Explanation
The division method h(k) = k mod table_size is one of the simplest and most common hash functions for integer keys.
Report an error in this question
HashingEasy
Q8. What is the purpose of a hash table?
- A.To store data in sorted ascending order
- B.To compress data for storage saving
- C.To sort data elements efficiently
- D.To provide fast insert, delete, and lookup✓ Correct
Explanation
Hash tables provide average O(1) time for insertion, deletion, and lookup operations.
Report an error in this question
HashingEasy
Q9. What happens when you insert a key that already exists in a hash table?
- A.The insertion is silently ignored completely
- B.Both old and new values are stored
- C.The old value is typically updated with new✓ Correct
- D.It causes a runtime error exception
Explanation
In most hash table implementations, inserting an existing key updates (overwrites) the associated value.
Report an error in this question
HashingMedium
Q10. What is open addressing in hash tables?
- A.Using multiple hash tables for distribution
- B.Finding another open slot when collision occurs✓ Correct
- C.Doubling the table size on every collision
- D.Using linked lists for collision resolution
Explanation
Open addressing resolves collisions by probing for the next available slot in the hash table itself, rather than using external data structures.
Report an error in this question
HashingEasy
Q11. What is chaining in hash tables?
- A.Linking multiple hash tables together
- B.Connecting hash functions in sequence
- C.Storing colliding elements in a linked list✓ Correct
- D.A type of hash function computation
Explanation
Chaining handles collisions by maintaining a linked list at each index; colliding elements are appended to the list at that index.
Report an error in this question
HashingEasy
Q12. What is the load factor of a hash table?
- A.The ratio of entries to number of slots✓ Correct
- B.The number of hash functions being used
- C.The total number of collisions occurred
- D.The total size of the hash table
Explanation
Load factor = (number of entries) / (number of slots). It measures how full the hash table is.
Report an error in this question
HashingMedium
Q13. What is the primary clustering problem in linear probing?
- A.Keys are stored in sorted order clusters
- B.Consecutive occupied slots form long clusters✓ Correct
- C.Hash values clustering near zero index
- D.Multiple hash functions produce same values
Explanation
Primary clustering occurs when consecutive occupied slots form long clusters, causing new insertions and lookups near those clusters to take longer.
Report an error in this question
HashingMedium
Q14. What is double hashing?
- A.Using two hash functions for probe step size✓ Correct
- B.Hashing the hash value itself recursively
- C.Hashing a value twice in succession
- D.Using two separate hash tables for storage
Explanation
Double hashing uses a second hash function to determine the step size for probing: h(k, i) = (h1(k) + i × h2(k)) mod m.
Report an error in this question
HashingMedium
Q15. What is quadratic probing?
- A.Using four different hash functions total
- B.Squaring the hash value before modding
- C.Using a quadratic hash function for keys
- D.Probing at positions h+1², h+2², h+3², etc.✓ Correct
Explanation
Quadratic probing uses a quadratic function to determine the next probe position: h(k) + 1², h(k) + 2², h(k) + 3², etc.
Report an error in this question
HashingMedium
Q16. What is rehashing?
- A.Hashing the same key multiple times in a row
- B.Removing all elements and starting fresh over
- C.Changing the hash function to a new one
- D.Creating a larger table and reinserting all elements✓ Correct
Explanation
Rehashing involves creating a new hash table (usually double the size) and reinserting all existing elements when the load factor gets too high.
Report an error in this question
HashingMedium
Q17. Why should the hash table size be a prime number?
- A.It is required by all hash functions
- B.It distributes hash values more uniformly✓ Correct
- C.It speeds up the hash value computation
- D.It makes the table smaller in memory
Explanation
A prime table size helps distribute keys more uniformly across the table, especially with the division method, reducing the likelihood of collisions.
Report an error in this question
HashingMedium
Q18. What is the multiplication method for hashing?
- A.h(k) = k mod (m × 2)
- B.h(k) = k^2 mod m
- C.h(k) = floor(m × (k × A mod 1)) where 0 < A < 1✓ Correct
- D.h(k) = k × m
Explanation
The multiplication method computes h(k) = floor(m × (k × A mod 1)), where A is a constant (commonly the golden ratio ≈ 0.618).
Report an error in this question
HashingMedium
Q19. What is the advantage of chaining over open addressing?
- A.Chaining is always faster for all operations
- B.Chaining uses less memory per element overall
- C.Chaining handles high load factors and deletion better✓ Correct
- D.Chaining has better CPU cache performance overall
Explanation
Chaining handles collisions gracefully even at high load factors, and deletion is straightforward (just remove from the linked list).
Report an error in this question
HashingHard
Q20. What is a Bloom filter?
- A.A type of hash table with chaining
- B.A comparison-based sorting algorithm
- C.A filter for removing duplicate elements
- D.A probabilistic structure testing set membership✓ Correct
Explanation
A Bloom filter uses multiple hash functions and a bit array to test membership. It can have false positives but never false negatives.
Report an error in this question
HashingHard
Q21. What is cuckoo hashing?
- A.A technique using random hash function selection
- B.A technique using two hash functions with displacement✓ Correct
- C.A hashing technique inspired by bird nesting
- D.A type of perfect hashing for static keys
Explanation
Cuckoo hashing uses two hash functions and tables. On collision, the new element displaces the existing one, which is then rehashed to its alternative location.
Report an error in this question
HashingHard
Q22. What is universal hashing?
- A.Hashing all elements to the same single bucket
- B.Using the same hash function across all applications
- C.Randomly selecting a hash function from a family of functions✓ Correct
- D.A single hash function that works for all data types
Explanation
Universal hashing randomly selects a hash function from a family of functions, guaranteeing that the probability of collision for any two keys is at most 1/m.
Report an error in this question
HashingMedium
Q23. What is a hash set?
- A.A multiset allowing duplicate elements
- B.A set using hashing for fast unique lookups✓ Correct
- C.A sorted set with ordered elements
- D.A set implemented using sorted arrays
Explanation
A hash set is a collection that stores unique elements using hashing, providing O(1) average time for add, remove, and contains operations.
Report an error in this question
HashingHard
Q24. What is consistent hashing?
- A.Using the same hash function consistently always
- B.A collision-free hashing technique for all inputs
- C.A hashing that always produces the same output
- D.A scheme remapping only a fraction of keys on change✓ Correct
Explanation
Consistent hashing maps both keys and nodes to a ring. When a node is added or removed, only keys near that node are remapped, minimizing disruption.
Report an error in this question
HashingHard
Q25. What is perfect hashing?
- A.A hash function that always distributes keys evenly
- B.A hash function with no collisions for any input set
- C.A hashing technique that requires no table at all
- D.A two-level scheme guaranteeing O(1) worst-case lookup✓ Correct
Explanation
Perfect hashing uses a two-level scheme with universal hashing at each level, achieving O(1) worst-case lookup time for a known, static set of keys.
Report an error in this question
HashingHard
Q26. What is the purpose of a cryptographic hash function?
- A.To speed up hash table lookups efficiently
- B.To compress files to smaller size format
- C.To produce collision-resistant irreversible fixed output✓ Correct
- D.To sort data in a deterministic order
Explanation
Cryptographic hash functions (e.g., SHA-256) produce fixed-size digests that are one-way (hard to reverse) and collision-resistant, used in security applications.
Report an error in this question
HashingHard
Q27. What is Robin Hood hashing?
- A.A two-level hashing scheme with perfect balance
- B.A charitable hashing distribution across buckets
- C.Stealing hash values from other tables entirely
- D.Open addressing where longer probes displace shorter ones✓ Correct
Explanation
Robin Hood hashing is an open addressing technique where a new element can displace an existing one if the new element's probe distance is longer, reducing variance in probe lengths.
Report an error in this question
HashingHard
Q28. What is hopscotch hashing?
- A.An open addressing scheme with bounded neighborhoods✓ Correct
- B.A random displacement hashing for load balance
- C.A hashing game-based approach to distribution
- D.A chaining variant using skip list buckets
Explanation
Hopscotch hashing ensures items are stored within a fixed-size neighborhood of their original hash bucket, combining benefits of open addressing and chaining with good cache performance.
Report an error in this question
HashingHard
Q29. What is the false positive probability of a Bloom filter with m bits, k hash functions, and n inserted elements?
- A.(1 - e^(-kn/m))^k approx✓ Correct
- B.n / m ratio
- C.1 / 2^k value
- D.k / m ratio
Explanation
The false positive probability is approximately (1 - e^(-kn/m))^k, where m is the number of bits, k is hash functions, and n is inserted elements.
Report an error in this question
HashingHard
Q30. What is the expected maximum chain length in a hash table with n elements and n slots using chaining?
- A.O(log n / log log n)✓ Correct
- B.O(√n)
- C.O(1)
- D.O(n)
Explanation
With uniform hashing and load factor 1, the expected maximum chain length is Θ(log n / log log n).
Report an error in this question