chapter
    Hashing and Collision Resolution PYQs for GATE CS

    Solve 5+ Hashing and Collision Resolution previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2026 Slot Set2 PYQ
    Level 4: Challenger

    The keys are inserted into a hash table using the hash function . The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is __________. <i>(answer in integer)</i>

    Question 2
    2026 Slot Set1 PYQ
    Level 4: Challenger
    Consider a hash table that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is .

    Consider the following sequence of insertions performed on :


    Which of the following positions in the hash table is/are empty after these insertions are performed?
    Question 3
    2025 Slot Set1 PYQ
    Level 4: Challenger
    In a double hashing scheme, and are the auxiliary hash functions. The size of the hash table is 11. The hash function for the -th probe in the open address table is . The following keys are inserted in the given order: 63, 50, 25, 79, 67, 24.

    The slot at which key 24 gets stored is ___________. (Answer in integer)
    Question 4
    2022 PYQ
    Level 4: Challenger

    Suppose we are given keys, hash table slots, and two simple uniform hash functions and . Further suppose our hashing scheme uses for the odd keys and for the even keys. What is the expected number of keys in a slot?

    Question 5
    2021 Slot Set1 PYQ
    Level 4: Challenger
    Consider a dynamic hashing approach for 4-bit integer keys:
    1. There is a main hash table of size 4.
    2. The 2 least significant bits of a key is used to index into the main hash table.
    3. Initially, the main hash table entries are empty.
    4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table entry is organized as a binary tree that grows on demand.
    5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees.
    6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit.
    7. A split is done only if it is needed, i.e., only when there is a collision.
    Consider the following state of the hash table.

    00 01 10 11 empty 0 1 0 1 0 1
    Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Hashing and Collision Resolution PYQs for GATE CS

    Solve 5+ Hashing and Collision Resolution previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Open Addressing Mechanics and Probe Sequences

    Open Addressing Mechanics and Probe Sequences

    Table with 11 slots. A key hashes to slot 3, but it is occupied.

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Linear probe: 3 → 4 → 5 → 6 → 7

    primary clustering consecutive slots fill into a block

    secondary clustering two keys hashing to 3 follow the identical path

    Consider a hash table with eleven slots, indexed from zero to ten. If we insert a key that hashes to slot three, but slot three is already occupied, we must check another slot. In open addressing, we check slots according to a fixed probe sequence. If the sequence checks slots three, four, five, and six in order, we are using linear probing. This creates primary clustering, where consecutive slots fill up, forming traffic jams. If two different keys both hash to slot three and follow the exact same sequence, they suffer from secondary clustering. In linear and quadratic probing, the probe sequence depends only on the initial hash value, not the key itself. Double hashing avoids this by making the step size a function of the key.

    Explain this more simply
    Imagine a parking lot where every car has an assigned spot. If your spot is taken, you do not leave the lot. You drive to the next available spot. Primary clustering is what happens when everyone assigned to the front row ends up parking in the back row because the front is full. Secondary clustering is when two different people, assigned to the same spot, follow the exact same driving path to find a new space.
    Go one level deeper
    The mathematical distinction between these clusterings dictates performance. Primary clustering degrades the expected probe length because the probability of hitting a filled block increases with the block size. Secondary clustering is less severe but still present in linear and quadratic probing because the probe sequence is a deterministic function of the initial hash value. Double hashing eliminates secondary clustering by making the step size a function of the key itself.

    Linear Probing Formula and Wrap-around

    Table size 11. Key hashes to slot 8. Slots 8, 9, 10 are full.

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    Probe 0: slot 8 (full) → Probe 1: slot 9 (full) → Probe 2: slot 10 (full) → Probe 3: slot 0 (wrap-around)

    h(k, i) = (h(k) + i) mod m

    For h(k)=8, m=11: i=0 → 8, i=1 → 9, i=2 → 10, i=3 → 0

    Suppose a table has size eleven. A key hashes to slot eight. If slot eight is full, linear probing checks slot nine, then ten, then wraps around to zero, then one. The general formula for the i-th probe is the initial hash plus i, all modulo the table size. For our key, the zero-th probe is eight. The first probe is nine. The second probe is ten. The third probe wraps around to zero. The step size is always exactly one. This constant step is what causes primary clustering, as any key hashing near a filled block will join that block.

    Explain this more simply
    Think of a circular track with eleven lanes. You start in your assigned lane. If it is blocked, you move to the very next lane. If you reach lane ten and it is blocked, your next step takes you back to lane zero. You never skip a lane.
    Go one level deeper
    Three-second check: Substitute zero into your formula. If the result is not exactly the initial hash value, your index offset is wrong. The most common error is starting the probe index at one instead of zero. If you start at one, your first check is the initial hash plus one, completely skipping the initial hash slot.

    Hashing and Collision Resolution: Solved Questions with Step-by-Step Explanations (5 Problems)

    Question 1 · Programming and Data Structures · 2026_Set2 NAT

    The keys are inserted into a hash table using the hash function . The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is __________. <i>(answer in integer)</i>

    Correct Answer:

    3.00

    Step-by-Step Solution

    Insight: Separate chaining appends colliding keys to a linked list at the hashed index; the longest chain is simply the maximum bucket size.

    Exam route: Compute for all 9 keys, tally the frequencies of each remainder, and pick the maximum frequency.

    Learning route:

    The hash function is .

    Compute the bucket for each key:

    Tallying the remainders:

    • Index 0: 0 keys
    • Index 1: 28, 19, 10 (3 keys)
    • Index 2: 0 keys
    • Index 3: 12 (1 key)
    • Index 4: 0 keys
    • Index 5: 5 (1 key)
    • Index 6: 15, 33 (2 keys)
    • Index 7: 0 keys
    • Index 8: 26, 17 (2 keys)

    The maximum number of keys in any bucket is 3 (at index 1).

    Thus, the length of the longest chain is 3.

    Tempting wrong path: A student might count the total number of collisions instead of the maximum chain length. There are 4 collisions (28 collides with 19, 10 collides with them, 33 collides with 15, 17 collides with 26), leading to an answer of 4. This breaks down because "longest chain" refers to the maximum bucket size, not the sum of collisions.

    Generalization: In separate chaining, the chain length at any index is exactly the frequency of that hash value.

    Verification: Re-checking , , . All correctly map to 1. No other bucket has 3 or more keys.

    Question 2 · Programming and Data Structures · 2026_Set1 MSQ
    Consider a hash table that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is .

    Consider the following sequence of insertions performed on :


    Which of the following positions in the hash table is/are empty after these insertions are performed?
    1. A.

      0

    2. B.

      10

    3. C.

      2

    4. D.

      1

    Correct Answer:

    ["C"]

    Step-by-Step Solution

    Insight: Linear probing resolves collisions by sequentially checking the next available slot, wrapping around the table if necessary.

    Exam route: Map each key to its initial hash, then shift right one slot at a time upon collision, keeping track of occupied indices to identify the empty ones.

    Learning route:

    Table size , indices to .

    .

    Insertions:

    • 1: . P[8] = 1.
    • 13: . P[9] = 13.
    • 22: . P[7] = 22.
    • 15: . P[0] = 15.
    • 11: . P[7] full. Probe 8 (full), 9 (full), 10 (empty). P[10] = 11.
    • 24: . P[9] full. Probe 10 (full), 0 (full), 1 (empty). P[1] = 24.

    Occupied slots: 0, 1, 7, 8, 9, 10.

    Empty slots: 2, 3, 4, 5, 6.

    Checking the options: 0 is occupied, 10 is occupied, 2 is empty, 1 is occupied. Only position 2 is empty.

    Tempting wrong path: Assuming index 0 remains empty because no key naturally hashes to it without wrap-around, but 15 hashes to 0 directly. Or assuming index 10 is empty because it is at the end, forgetting that 11 wraps into it.

    Generalization: Linear probing clusters can wrap around the end of the array; always apply the modulo operator when incrementing the probe index.

    Verification: Count the keys. 6 keys inserted, so exactly 6 slots must be occupied and 5 empty. Our occupied list has 6 distinct slots.

    Question 3 · Programming and Data Structures · 2025_Set1 NAT
    In a double hashing scheme, and are the auxiliary hash functions. The size of the hash table is 11. The hash function for the -th probe in the open address table is . The following keys are inserted in the given order: 63, 50, 25, 79, 67, 24.

    The slot at which key 24 gets stored is ___________. (Answer in integer)
    Correct Answer:

    10.00

    Step-by-Step Solution

    Insight: Double hashing uses a secondary hash function to determine the step size for probing, avoiding primary clustering.

    Exam route: Trace the table state by inserting each key sequentially, then apply the double hashing formula for the target key until an empty slot is found.

    Learning route:

    Table size .

    Insertions:

    • 63: . . Table[8] = 63.
    • 50: . . Table[6] = 50.
    • 25: . . Table[3] = 25.
    • 79: . . Table[2] = 79.
    • 67: . . Table[1] = 67.

    Now insert 24:

    Probe sequence for 24:

    • . Occupied by 79.
    • . Occupied by 50.
    • . Empty!

    Key 24 is stored at slot 10.

    Tempting wrong path: Forgetting the in and using . The probes would be . Since 8 is occupied by 63, the next is . This leads to slot 0, which is incorrect because the formula explicitly includes the to ensure the step size is never 0.

    Generalization: In double hashing, must never evaluate to 0, which is why formulas often include a or use a prime modulus.

    Verification: Check if any earlier key was displaced. Open addressing only places keys in empty slots. 10 is indeed empty.

    Question 4 · Programming and Data Structures · 2022 MCQ

    Suppose we are given keys, hash table slots, and two simple uniform hash functions and . Further suppose our hashing scheme uses for the odd keys and for the even keys. What is the expected number of keys in a slot?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    B

    Step-by-Step Solution

    Insight: Simple uniform hashing guarantees that every key independently has a probability of landing in any specific slot, regardless of the deterministic rule used to pick the hash function.

    Exam route: Recognize that any simple uniform hash function distributes keys evenly in expectation. The expected load is simply total keys divided by total slots.

    Learning route:

    Let be an indicator random variable that is 1 if key hashes to slot , and 0 otherwise.

    Because both and are simple uniform hash functions, for any key , the probability that it maps to slot is exactly , whether it uses or .

    Thus, for all .

    The total number of keys in slot is .

    By linearity of expectation:

    .

    Tempting wrong path: Assuming the parity split halves the keys per slot, leading to . While half the keys use and half use , both functions map to the same slots with probability , so the total expectation remains .

    Generalization: Linearity of expectation holds regardless of dependencies or deterministic routing rules, as long as the marginal probability for each item remains uniform.

    Verification: If , expected keys per slot is 1. Formula gives . Matches intuition.

    Question 5 · Programming and Data Structures · 2021_Set1 MSQ
    Consider a dynamic hashing approach for 4-bit integer keys:
    1. There is a main hash table of size 4.
    2. The 2 least significant bits of a key is used to index into the main hash table.
    3. Initially, the main hash table entries are empty.
    4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table entry is organized as a binary tree that grows on demand.
    5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees.
    6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit.
    7. A split is done only if it is needed, i.e., only when there is a collision.
    Consider the following state of the hash table.

    00 01 10 11 empty 0 1 0 1 0 1
    Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?
    1. A.

      5, 9, 4, 13, 10, 7

    2. B.

      9, 5, 10, 6, 7, 1

    3. C.

      10, 9, 6, 7, 5, 13

    4. D.

      9, 5, 13, 6, 10, 14

    Correct Answer:

    ["C"]

    Step-by-Step Solution

    Insight: Dynamic hashing with a binary tree resolves collisions by branching on successive higher-order bits only when a leaf node experiences a collision.

    Exam route: Decode the tree structure from the diagram to find the required bit patterns for each leaf, then test each option's sequence to see which one perfectly builds that exact tree without extra splits.

    Learning route:

    The diagram shows a main table of 4 slots indexed by the 2 LSBs ().

    • Index 0 (00): Empty.
    • Index 1 (01): Splits on . Left child () is a leaf. Right child () splits on .
    • Index 2 (10): Splits on . Left child () is a leaf. Right child () is a leaf.
    • Index 3 (11): Leaf.

    Test Option C: 10, 9, 6, 7, 5, 13

    • 10 (1010): idx 2. Leaf.
    • 9 (1001): idx 1. Leaf.
    • 6 (0110): idx 2. Collides with 10. Splits on . 10 has , 6 has . Matches diagram!
    • 7 (0111): idx 3. Leaf. Matches diagram!
    • 5 (0101): idx 1. Collides with 9. Splits on . 9 has , 5 has .
    • 13 (1101): idx 1. Collides with 5. Splits on . 5 has , 13 has . Matches diagram!

    Tempting wrong path: Selecting a sequence that includes 14 (1110), which hashes to index 2 with . This would collide with 6 (0110) at the right child of index 2, forcing an unwanted split on , which the diagram does not show.

    Generalization: In dynamic hashing, splits are strictly demand-driven; a node only branches when a collision occurs at that exact leaf, using the next available bit.

    Verification: Option C perfectly reconstructs the tree without leaving any index empty that should be occupied, and without triggering any unshown splits.

    More previous year questions (pyqs) in this unit