Back to Practice Data Structures

Hashing - Practice MCQs for CCAT

50 Questions Section B: Programming Data Structures

Hashing Question Bank for C-CAT

Topic-wise Hashing MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
Average time complexity of hash table operations:
AO(n)
BO(1)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(1)

Hash table provides O(1) average case for insert, delete, search.

Q2.
Collision in hashing occurs when:
AHash table is empty
BTable is full
CKey not found
DTwo keys map to same index
Show Answer & Explanation

Correct Answer: D - Two keys map to same index

Collision occurs when different keys produce the same hash index.

Q3.
Linear probing handles collision by:
AUsing linked list
BRehashing
CChecking next slot sequentially
DIgnoring
Show Answer & Explanation

Correct Answer: C - Checking next slot sequentially

Linear probing checks next consecutive slots until empty slot found.

Q4.
Chaining handles collision using:
ALinked lists at each index
BArrays
CTrees
DMultiple tables
Show Answer & Explanation

Correct Answer: A - Linked lists at each index

Chaining stores multiple elements at same index using linked list.

Q5.
Load factor of hash table:
Am/n
Bn/m
Cn+m
Dn×m
Show Answer & Explanation

Correct Answer: B - n/m

Load factor = n/m where n is elements and m is table size.

Q6.
Good hash function should:
AAlways collide
BUse more memory
CBe slow
DDistribute keys uniformly
Show Answer & Explanation

Correct Answer: D - Distribute keys uniformly

Good hash function distributes keys uniformly to minimize collisions.

Q7.
Worst case time for hash table operations:
AO(1)
BO(log n)
CO(n)
DO(n²)
Show Answer & Explanation

Correct Answer: C - O(n)

Worst case (all keys collide) is O(n).

Q8.
Double hashing uses:
AOne hash function
BChaining
CNo hash function
DTwo hash functions
Show Answer & Explanation

Correct Answer: D - Two hash functions

Double hashing uses two hash functions to calculate probe sequence.

Q9.
Which is NOT a collision resolution technique?
ALinear probing
BQuadratic probing
CChaining
DSorting
Show Answer & Explanation

Correct Answer: D - Sorting

Sorting is not a collision resolution technique.

Q10.
Primary clustering is a problem in:
ALinear probing
BChaining
CDouble hashing
DQuadratic probing
Show Answer & Explanation

Correct Answer: A - Linear probing

Linear probing suffers from primary clustering where consecutive slots fill up.

Q11.
Secondary clustering occurs in:
ALinear probing
BChaining
CQuadratic probing
DDouble hashing
Show Answer & Explanation

Correct Answer: C - Quadratic probing

Quadratic probing suffers from secondary clustering where keys with same hash follow same probe sequence.

Q12.
Rehashing is performed when:
ALoad factor exceeds threshold
BTable is empty
CNo collision occurs
DKey is deleted
Show Answer & Explanation

Correct Answer: A - Load factor exceeds threshold

Rehashing creates a larger table when load factor becomes too high to maintain efficiency.

Q13.
For hash table size, which is preferred?
APower of 2
BAny number
CEven number
DPrime number
Show Answer & Explanation

Correct Answer: D - Prime number

Prime number table sizes help distribute keys more uniformly and reduce collisions.

Q14.
Universal hashing helps prevent:
AAdversarial attacks
BMemory usage
CFast access
DChaining
Show Answer & Explanation

Correct Answer: A - Adversarial attacks

Universal hashing randomly selects hash function to prevent adversarial worst-case inputs.

Q15.
Cuckoo hashing uses:
AOne table with chaining
BTwo hash functions and tables
CLinear probing only
DNo collision handling
Show Answer & Explanation

Correct Answer: B - Two hash functions and tables

Cuckoo hashing uses two hash functions and moves elements between positions on collision.

Q16.
Perfect hashing guarantees:
AO(n) worst case
BDynamic insertion
CNo memory usage
DO(1) worst case lookup
Show Answer & Explanation

Correct Answer: D - O(1) worst case lookup

Perfect hashing provides O(1) worst-case lookup with no collisions for static sets.

Q17.
In open addressing, deleted elements are marked as:
ATombstone/Deleted
BNull
CEmpty
DOccupied
Show Answer & Explanation

Correct Answer: A - Tombstone/Deleted

Tombstone markers allow probe sequences to continue past deleted elements.

Q18.
Hash function h(k) = k mod m, if m = 10 and k = 47:
A4
B47
C7
D10
Show Answer & Explanation

Correct Answer: C - 7

47 mod 10 = 7, so the key 47 maps to index 7.

Q19.
Which is true about chaining?
ALoad factor must be < 1
BNo extra memory needed
CLoad factor can exceed 1
DFaster than open addressing always
Show Answer & Explanation

Correct Answer: C - Load factor can exceed 1

With chaining, load factor can exceed 1 as multiple elements can be at same index.

Q20.
Bloom filter is used for:
AExact membership
BProbabilistic membership testing
CSorting
DGraph traversal
Show Answer & Explanation

Correct Answer: B - Probabilistic membership testing

Bloom filter is a space-efficient probabilistic structure for membership testing with possible false positives.

Q21.
What is the primary purpose of a hash function?
ATo sort data
BTo map keys to indices in a hash table
CTo encrypt data
DTo compress data
Show Answer & Explanation

Correct Answer: B - To map keys to indices in a hash table

A hash function maps keys to indices (hash values) in a hash table, enabling fast data retrieval in approximately O(1) time.

Q22.
What is a collision in hashing?
AWhen two hash tables merge
BWhen two different keys map to the same hash value
CWhen the hash table is full
DWhen a key is deleted
Show Answer & Explanation

Correct Answer: B - When two different keys map to the same hash value

A collision occurs when two different keys produce the same hash value, mapping to the same index in the hash table.

Q23.
Which of the following is a method to resolve collisions in hashing?
ABinary search
BSorting
CRecursion
DChaining
Show Answer & Explanation

Correct Answer: D - Chaining

Chaining (separate chaining) resolves collisions by maintaining a linked list at each hash table index to store all keys that hash to that index.

Q24.
In open addressing, linear probing resolves collisions by:
AUsing a linked list
BRehashing with a different function
CSearching the next available slot sequentially
DDoubling the table size
Show Answer & Explanation

Correct Answer: C - Searching the next available slot sequentially

Linear probing resolves collisions by checking the next slot (index + 1, index + 2, ...) sequentially until an empty slot is found.

Q25.
What problem does linear probing suffer from?
AStack overflow
BPrimary clustering
CMemory leak
DDeadlock
Show Answer & Explanation

Correct Answer: B - Primary clustering

Linear probing suffers from primary clustering, where consecutive occupied slots form clusters, degrading performance as search time increases.

Q26.
Quadratic probing resolves collisions by:
AChecking slots at intervals of 1, 2, 3, ...
BUsing a second hash function
CChecking slots at intervals of 1², 2², 3², ...
DCreating a linked list
Show Answer & Explanation

Correct Answer: C - Checking slots at intervals of 1², 2², 3², ...

Quadratic probing checks slots at positions h(k)+1², h(k)+2², h(k)+3², etc., reducing primary clustering compared to linear probing.

Q27.
Double hashing uses:
ATwo hash tables
BTwo linked lists
CTwo keys for each value
DTwo hash functions
Show Answer & Explanation

Correct Answer: D - Two hash functions

Double hashing uses a second hash function to determine the step size for probing, providing a more uniform distribution and reducing clustering.

Q28.
The load factor of a hash table is defined as:
ANumber of elements / table size
BNumber of elements × table size
CTable size / number of elements
DNumber of collisions / table size
Show Answer & Explanation

Correct Answer: A - Number of elements / table size

The load factor α = n/m where n is the number of elements stored and m is the size of the hash table. It measures how full the table is.

Q29.
What is the ideal time complexity of search, insert, and delete operations in a hash table?
AO(1)
BO(log n)
CO(n)
DO(n log n)
Show Answer & Explanation

Correct Answer: A - O(1)

With a good hash function and low load factor, hash table operations (search, insert, delete) achieve O(1) average-case time complexity.

Q30.
Which hash function technique uses the remainder after division?
AMid-square method
BDivision method
CFolding method
DMultiplication method
Show Answer & Explanation

Correct Answer: B - Division method

The division method computes hash as h(k) = k mod m, where m is the table size. It's simple and commonly used.

Q31.
In separate chaining, each slot of the hash table contains:
AA single key
BA pointer to a linked list
CA binary search tree
DA sorted array
Show Answer & Explanation

Correct Answer: B - A pointer to a linked list

In separate chaining, each slot contains a pointer to a linked list (or chain) that stores all elements hashing to that index.

Q32.
When should a hash table be resized (rehashed)?
AWhen the table is empty
BWhen a collision occurs
CAfter every insertion
DWhen the load factor exceeds a threshold
Show Answer & Explanation

Correct Answer: D - When the load factor exceeds a threshold

Rehashing is typically done when the load factor exceeds a threshold (e.g., 0.75), to maintain O(1) average-case performance.

Q33.
What is rehashing?
ACreating a larger table and reinserting all elements
BDeleting all elements
CReversing the hash function
DSorting the hash table
Show Answer & Explanation

Correct Answer: A - Creating a larger table and reinserting all elements

Rehashing involves creating a new, larger hash table and reinserting all existing elements using the hash function with the new table size.

Q34.
A good hash function should have which property?
AAlways produce the same hash for different keys
BMinimize the table size
CAlways produce consecutive hash values
DDistribute keys uniformly across the table
Show Answer & Explanation

Correct Answer: D - Distribute keys uniformly across the table

A good hash function should distribute keys uniformly across the hash table to minimize collisions and achieve O(1) average performance.

Q35.
In the multiplication method of hashing, the hash is computed as:
Ah(k) = ⌊m(kA mod 1)⌋ where 0 < A < 1
Bh(k) = k mod m
Ch(k) = k × m
Dh(k) = k / m
Show Answer & Explanation

Correct Answer: A - h(k) = ⌊m(kA mod 1)⌋ where 0 < A < 1

The multiplication method computes h(k) = ⌊m(kA mod 1)⌋ where A is a constant between 0 and 1. Knuth suggests A ≈ (√5 - 1)/2.

Q36.
Which collision resolution technique does NOT suffer from clustering?
ADouble hashing
BQuadratic probing
CLinear probing
DAll suffer from clustering
Show Answer & Explanation

Correct Answer: A - Double hashing

Double hashing virtually eliminates clustering because the probe sequence depends on two independent hash functions, producing a more uniform distribution.

Q37.
The worst-case time complexity of search in a hash table using separate chaining is:
AO(1)
BO(n)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: B - O(n)

In the worst case, all n elements hash to the same index, creating a single linked list of length n, making search O(n).

Q38.
For the division method h(k) = k mod m, which value of m is generally preferred?
AA power of 2
BAn even number
CA prime number
DA multiple of 10
Show Answer & Explanation

Correct Answer: C - A prime number

A prime number is preferred for m in the division method as it distributes keys more uniformly and avoids patterns caused by powers of 2.

Q39.
What is a perfect hash function?
AA function that sorts the keys
BA function that uses no memory
CA function with no collisions for a given set of keys
DA function that runs in O(log n)
Show Answer & Explanation

Correct Answer: C - A function with no collisions for a given set of keys

A perfect hash function maps each key in a specific set to a distinct hash value with no collisions. It's achievable when the key set is known in advance.

Q40.
In open addressing, what happens when the hash table is full?
ANo more elements can be inserted
BElements are automatically deleted
CA linked list is created
DElements overflow to another table
Show Answer & Explanation

Correct Answer: A - No more elements can be inserted

In open addressing, when the table is full, no more elements can be inserted since all slots are occupied. Rehashing is needed to accommodate more elements.

Q41.
Which of the following is NOT an open addressing technique?
ALinear probing
BSeparate chaining
CQuadratic probing
DDouble hashing
Show Answer & Explanation

Correct Answer: B - Separate chaining

Separate chaining is NOT an open addressing technique. It uses linked lists at each slot, while open addressing stores all elements within the table itself.

Q42.
The mid-square method of hashing works by:
AMultiplying key by table size
BFinding the square root of the key
CSquaring the key and extracting middle digits
DDividing key by its square
Show Answer & Explanation

Correct Answer: C - Squaring the key and extracting middle digits

The mid-square method squares the key and then extracts the middle digits of the result to use as the hash value.

Q43.
What is the expected number of probes for a successful search in open addressing with load factor α?
A1/α
Bα
C(1/α) × ln(1/(1-α))
D1 + α
Show Answer & Explanation

Correct Answer: C - (1/α) × ln(1/(1-α))

For uniform hashing with open addressing, the expected number of probes for a successful search is approximately (1/α) × ln(1/(1-α)).

Q44.
Cuckoo hashing uses:
ATwo hash functions and two tables
BOne hash function and one table
CThree hash functions and one table
DNo hash function
Show Answer & Explanation

Correct Answer: A - Two hash functions and two tables

Cuckoo hashing uses two hash functions and two tables. Each key has two possible positions, and collisions are resolved by displacing existing keys.

Q45.
Which of the following applications uses hashing?
ADatabase indexing
BSymbol tables in compilers
CCaching
DAll of the above
Show Answer & Explanation

Correct Answer: D - All of the above

Hashing is widely used in database indexing, compiler symbol tables, caching mechanisms, and many other applications requiring fast lookups.

Q46.
In a hash table with m slots and n keys, what is the average chain length in separate chaining?
Am/n
Bn × m
Cn/m
Dm + n
Show Answer & Explanation

Correct Answer: C - n/m

The average chain length in separate chaining equals the load factor n/m, which represents the average number of keys per slot.

Q47.
The folding method of hashing involves:
ASorting the key digits
BFolding the hash table in half
CMultiplying the key by itself
DDividing the key into parts and combining them
Show Answer & Explanation

Correct Answer: D - Dividing the key into parts and combining them

The folding method divides the key into equal-sized parts (except possibly the last) and combines them (usually by addition) to get the hash value.

Q48.
What is secondary clustering?
AWhen keys with the same initial hash follow the same probe sequence
BClustering that occurs in separate chaining
CClustering in the secondary hash table
DClustering due to deletions
Show Answer & Explanation

Correct Answer: A - When keys with the same initial hash follow the same probe sequence

Secondary clustering occurs when keys that hash to the same initial position follow the same probe sequence. Quadratic probing suffers from this.

Q49.
When deleting an element from a hash table using open addressing, we should:
ASimply remove the element
BMark the slot as deleted (lazy deletion)
CRehash the entire table
DShift all subsequent elements
Show Answer & Explanation

Correct Answer: B - Mark the slot as deleted (lazy deletion)

In open addressing, we use lazy deletion (marking as deleted) rather than simply removing, because removing would break the probe sequence for other elements.

Q50.
A universal hash function family ensures:
ANo collisions ever occur
BThe probability of collision for any two keys is at most 1/m
CAll keys hash to the same value
DThe hash function runs in O(1)
Show Answer & Explanation

Correct Answer: B - The probability of collision for any two keys is at most 1/m

A universal hash function family guarantees that for any two distinct keys, the probability of collision is at most 1/m, where m is the table size.

Showing 1-10 of 50 questions