Data Structures

Hashing — Practice MCQs for CCAT

20 Questions Section B: Programming Data Structures

Practice 20 Hashing multiple-choice questions designed for CDAC CCAT exam preparation. Click "Show Answer" to reveal the correct option with detailed explanation.

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

Correct Answer: A — O(1)

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

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

Correct Answer: B — 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
BChecking next slot sequentially
CRehashing
DIgnoring
Show Answer & Explanation

Correct Answer: B — Checking next slot sequentially

Linear probing checks next consecutive slots until empty slot found.

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

Correct Answer: B — Linked lists at each index

Chaining stores multiple elements at same index using linked list.

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

Correct Answer: A — n/m

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

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

Correct Answer: B — Distribute keys uniformly

Good hash function distributes keys uniformly to minimize collisions.

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

Correct Answer: B — O(n)

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

Q8.
Double hashing uses:
AOne hash function
BTwo hash functions
CNo hash function
DChaining
Show Answer & Explanation

Correct Answer: B — 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:
AChaining
BLinear probing
CDouble hashing
DQuadratic probing
Show Answer & Explanation

Correct Answer: B — 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:
ATable is empty
BLoad factor exceeds threshold
CNo collision occurs
DKey is deleted
Show Answer & Explanation

Correct Answer: B — 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
BPrime number
CEven number
DAny number
Show Answer & Explanation

Correct Answer: B — Prime number

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

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

Correct Answer: B — 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
BO(1) worst case lookup
CNo memory usage
DDynamic insertion
Show Answer & Explanation

Correct Answer: B — 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:
ANull
BTombstone/Deleted
CEmpty
DOccupied
Show Answer & Explanation

Correct Answer: B — 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
B7
C47
D10
Show Answer & Explanation

Correct Answer: B — 7

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

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

Correct Answer: B — 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.