GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATA STRUCTURES

Simulate linear probing with wraparound

2 questions solved the same way, newest first. Back to Data Structures

How these are solved

For each key compute its home bucket, advance modulo table size to the first free slot, insert, then read requested table/empty slots. Unspecified-probing 2007 and ambiguous uppercase-hash 1996 are excluded.

1 mark · MSQ
Report issue

Linear probing with wraparound

Hashing

Question 24, GATE 2026: An initially empty table has indices 0–10, hash h(x)=(x+7) mod 11, and linear probing. Insert 1,13,22,15,11,24 in that order. Which listed positions are empty: A 0, B 10, C 2, D 1?
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C

Step through it (8 steps)

Givens and goal

An initially empty table has indices 0–10, hash h(x)=(x+7) mod 11, and linear probing. Insert 1,13,22,15,11,24 in that order. Which listed positions are empty: A 0, B 10, C 2, D 1?

Approach

Trace each home slot and each collision in insertion order, wrapping from index 10 to 0.

Step-by-step solution

1. Insert 1: h(1)=8, so place 1 at slot 8. Insert 13: h(13)=20 mod 11=9, so place 13 at 9.
2. Insert 22: h(22)=29 mod 11=7, so place 22 at 7. Insert 15: h(15)=22 mod 11=0, so place 15 at 0.
3. Insert 11: h(11)=18 mod 11=7. Slots 7,8,9 already contain 22,1,13. The first empty slot encountered is 10, so store 11 there.
4. Insert 24: h(24)=31 mod 11=9. Slots 9 and 10 are occupied; probing wraps to 0, which is also occupied. Slot 1 is empty, so place 24 at 1.
5. The final table is:

    index:  0   1   2  3  4  5  6   7   8   9   10
    value: 15  24   -  -  -  -  -  22   1  13   11

6. Of the four listed indices, only 2 is empty. Select C. The probing rule advances from the current candidate slot; it does not recompute a different hash after each collision.

Original paper, page 19 · Answer key

2 marks · MCQ
Report issue

Linear-probing hash insertion

Hashing

Question 36, GATE 2009: Insert 12, 18, 13, 2, 3, 23, 5, 15 in an empty 10-slot table using h(k)=k mod 10 and linear probing. Candidate A stores 2:2, 3:23, 5:15, 8:18; B stores 2:12, 3:13, 5:5, 8:18; C stores slots 2–9 as 12, 13, 2, 3, 23, 5, 18, 15; D chains 2:[12, 2], 3:[13, 3, 23], 5:[5, 15], 8:[18]. Other slots empty. Which is correct?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (10 steps)

Insertions place 12 at 2, 18 at 8, 13 at 3, 2 at 4, 3 at 5, 23 at 6, 5 at 7 and 15 at 9 after probing past occupied slots 5 through 8. The final slots 2–9 are 12, 13, 2, 3, 23, 5, 18, 15, exactly option C.

Probe consecutive slots until empty. First 12→2 and 18→8; 13→3. Key 2 collides at 2 and 3, so goes 4. Key 3 goes 5; 23 goes 6; 5 goes 7. Finally 15 probes 5, 6, 7, 8 before reaching 9. This yields candidate C. D instead uses chaining, which is explicitly not the requested collision strategy; A/B discard keys rather than preserving them in later empty slots.

Original paper, page 8