GATE / CS ARCHIVE

SUBJECT COLLECTION

Data Structures · Hashing

18 questions, newest first

GATE CSE has asked 18 questions on Hashing (Data Structures) from 1996 to 2026, in 15 of the 46 papers; the most recent is in GATE CSE 2026 Set 2. In the last five years it carried 0.6 marks per 100-mark paper on average, against 0.7 since 2003. Since 2014 the questions have been 4 NAT, 4 MCQ and 2 MSQ. 4 groups of questions here are solved the same way; “One per method” keeps the newest of each.

Browse topics
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

1 mark · NAT
Report issue

Longest chain after hashing

Hashing

Question 30, GATE 2026: Insert keys 5,28,19,15,26,33,12,17,10 into a table with h(k)=k mod 9, resolving collisions by chaining. Find the longest chain length.
Tap to enlarge
Answer & solution

Official answer: 3

Step through it (11 steps)

Givens and goal

Insert keys 5,28,19,15,26,33,12,17,10 into a table with h(k)=k mod 9, resolving collisions by chaining. Find the longest chain length.

Approach

Group all keys by their remainder rather than by insertion adjacency.

Step-by-step solution

1. The nine remainders in order are 5,1,1,6,8,6,3,8,1. For example 28=3×9+1, 33=3×9+6, and 17=1×9+8.
2. Bucket 1 receives 28,19,10; bucket 3 receives 12; bucket 5 receives 5; bucket 6 receives 15,33; bucket 8 receives 26,17. Buckets 0,2,4,7 remain empty.
3. The nonempty chain lengths are therefore 3,1,1,2,2, summing to 9 as a consistency check with the number of inserted keys.
4. The maximum is 3. Whether chaining inserts at the head or tail changes order inside a bucket but not its length. Do not apply linear probing: the problem explicitly stores collisions in chains.

Original paper, page 22 · Answer key

2 marks · NAT
Report issue

Tracing double-hash probing positions

Hashing

Question 65, GATE 2025: An initially empty hash table has m=11 slots. h1(k)=k mod 11, h2(k)=1+(k mod 7), and probe i uses [h1(k)+i·h2(k)] mod 11, starting at i=0. Insert 63,50,25,79,67,24 in that order. In which slot does 24 end up? The formula yields a zero-based index; the official range also accepts the corresponding one-based slot number.
Tap to enlarge
Answer & solution

Official answer: 10 to 11

Our answer: 10

Step through it (8 steps)

Approach: Insert the earlier keys first, because their occupied positions determine how many probes key 24 needs.
For the first five keys the primary hash locations are 63 mod 11=8, 50 mod 11=6, 25 mod 11=3, 79 mod 11=2 and 67 mod 11=1. All differ, so each key is placed on its first probe. Occupied indices are therefore {1,2,3,6,8}.
For 24, h1=24 mod 11=2 and h2=1+(24 mod 7)=1+3=4. Probe i=0 checks index 2, occupied by 79. Probe i=1 checks (2+4) mod 11=6, occupied by 50. Probe i=2 checks (2+8) mod 11=10, which is empty, so 24 is stored there.
The derived index is 10. This is the eleventh slot if slots are described with one-based ordinal numbers. Preserve the official accepted interval 10–11, but use 10 when interpreting the given modulo formula literally. The second hash is the step size, not a replacement initial index.

Original paper, page 64 · Answer key

1 mark · MCQ
Report issue

Hashing

Question 16, GATE 2022: Hash n keys into m slots, using simple-uniform hash function h1 for odd keys and h2 for even keys. Find the expected occupancy of a fixed slot. A m/n; B n/m; C 2n/m; D n/(2m).
Tap to enlarge
Your answer
Answer & solution

Official answer: B

For a fixed slot, each key maps there with probability 1/m under whichever uniform hash function applies to its parity. Summing n indicator expectations gives n/m. Independence between all indicators is unnecessary for this expectation. Thus B.

Let Ii=1 if key i lands in the chosen slot, and 0 otherwise. Occupancy X=ΣIi. Whether i is odd or even, E[Ii]=1/m, so E[X]=ΣE[Ii]=n/m. Using two functions does not double the number of keys or halve the table.

Original paper, page 13 · Answer key

2 marks · MSQ
Report issue

Hashing

Question 47, GATE 2021: Dynamic hashing uses a four-entry table indexed by the lowest two bits of four-bit integer keys. Collisions split into a binary tree by the third-lowest bit (0 left,1 right), then the fourth-lowest bit; split only when required. Target diagram: bucket 00 empty; bucket 01 splits at bit 3, with a leaf on branch 0 and a bit-4 split with two leaves on branch 1; bucket 10 splits at bit 3 into two leaves; bucket 11 has one leaf. Which insertion sequence yields it? A 5,9,4,13,10,7; B 9,5,10,6,7,1; C 10,9,6,7,5,13; D 9,5,13,6,10,14.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: C

The displayed shape requires bucket 00 empty; bucket 01 with one key having third-lowest bit 0 and two keys having third-lowest bit 1, separated by the fourth bit; bucket 10 with one key on each third-bit branch; and bucket 11 with one key. C supplies bucket01={9(1001), 5(0101), 13(1101)}, bucket10={10(1010), 6(0110)}, and bucket11={7(0111)}, exactly that structure. A puts 4 in bucket00, B splits the zero third-bit branch of bucket01 because it contains 1 and 9, and D leaves bucket11 empty while putting three keys in bucket10. Only C matches.

Process C explicitly: 10=1010 enters bucket10; 9=1001 enters bucket01; 6=0110 collides in bucket10 but differs from 10 in bit3, making its two leaves. Key 7=0111 occupies bucket11. Key 5=0101 collides with 9 in bucket01 and goes to its bit3=1 branch, whereas 9 has bit3=0. Finally 13=1101 joins 5 on bit3=1 and differs in bit4, producing exactly the extra split. A premature split without collision would violate the stated rule.

Original paper, page 38 · Answer key

1 mark · NAT
Report issue

Hashing

Question 23, GATE 2020: Double hashing uses h1(k)=k mod 23, h2(k)=1+(k mod 19), and table size 23. Probe numbering starts at 0. What address is returned at probe 1 for key 90?
Tap to enlarge
Answer & solution

Official answer: 13

Worked explanation

Double hashing uses h(k,i)=(h1(k)+i·h2(k)) mod m. Since 90=3×23+21, h1=21. Since 90=4×19+14, h2=1+14=15. The requested i=1 is the second probe, because i=0 gives the initial position. Add the step once and wrap around: (21+15) mod 23=13. Further probes would be 5,20,…, but their occupancy is irrelevant because only the address of a specified probe is requested.

Derivation and answer

h1(90)=90 mod23=21 and h2(90)=1+(90 mod19)=15. Probe1 is(21+1·15)mod23=36mod23=13. Probe0 would have been 21.

Original paper, page 8 · Answer key

2 marks · MCQ
Report issue

Hashing

Question 50, GATE 2015: Which hash best distributes integers i=0…2020 over buckets 0…9? A i²mod 10; B i³mod 10; C11i²mod 10; D12 imod 10.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Cubing permutes decimal residues: 0, 1, 8, 7, 4, 5, 6, 3, 2, 9. Therefore each block of 10 consecutive keys places one in each bucket. Among 2021 keys bucket 0 gets 203 and every other bucket 202, optimally balanced. Squares use only six residues, 11i² is identical modulo 10, and 12i only reaches even buckets. Thus B.

Only the last decimal digit matters modulo 10. Cubes of residues 0 through 9 give 0, 1, 8, 7, 4, 5, 6, 3, 2, 9, which is a permutation. Each full ten-key block therefore hits every bucket once. The 2021 keys consist of 202 full blocks plus one extra key 0 mod 10, giving counts 203, 202, …, 202, as balanced as possible. Squaring collapses residues, 11i²has the same residues as i², and 12i≡2i can only reach even buckets.

Original paper, page 44 · Answer key

1 mark · NAT
Report issue

Hashing

Question 22, GATE 2015: A hash table T has 25 slots and stores 2000 elements. Find its load factor α.
Tap to enlarge
Answer & solution

Official answer: 80

1. Load factor measures the average number of elements per table slot, rather than the fraction of slots that are nonempty. With separate chaining, several elements may share a slot, so a load factor greater than one is meaningful.

2. Load factor is number of stored elements divided by number of slots: 2000/25=80. This is possible with chaining rather than a one-element-per-slot open-addressed table.

Original paper, page 60 · Answer key

2 marks · MCQ
Report issue

Hashing

Question 40, GATE 2014: A nine-slot hash table uses h(k)=k mod 9 and chaining. Insert keys 5,28,19,15,20,33,12,17,10 in that order. What are the maximum, minimum and average chain lengths over all slots? A: 3,0,1. B: 3,3,3. C: 4,0,1. D: 3,0,2.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (11 steps)

1. Method and setup. Compute each key’s remainder, then count keys in each slot. Chaining does not probe or relocate a colliding key to another slot. Include empty slots when finding the minimum and when averaging: average chain length over the table is total keys divided by total slots.

2. Work through the result and its assumptions. The residues modulo 9 are 5, 1, 1, 6, 2, 6, 3, 8, 1. Slot1 has 3 keys; slots 0, 4, 7 are empty; all 9 slots together hold 9 keys, so average length 1. Maximum3, minimum 0, average 1: A.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Hashing

Question 40, GATE 2014: A 100-slot hash table resolves collisions by chaining and uses simple uniform hashing. What is the probability that slots 1,2,3 are all empty after three insertions? A 97³/100³; B (99×98×97)/100³; C (97×96×95)/100³; D (97×96×95)/(3!×100³).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step 1: For a given insertion, 97 of the 100 equally likely slots avoid the three prohibited slots, so its avoidance probability is 97/100. Step 2: Under simple uniform hashing the three placements are independent. Chaining permits multiple inserted keys to use the same allowed slot, so the allowed count does not decrease after an insertion. Step 3: Multiply the three factors: (97/100)³, option A. Using 97,96,95 would incorrectly require distinct occupied slots.

Original paper, page 62 · Answer key

2 marks · MCQ
Report issue

Linear-probing insertion sequence

Hashing

Question 52, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. Which sequence could have produced this table?
Options: (A) 46,42,34,52,23,33; (B) 34,42,23,52,33,46; (C) 46,34,42,23,52,33; (D) 42,46,33,23,34,52.
Question 52, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. Which sequence could have produced this table?
Options: (A) 46,42,34,52,23,33; (B) 34,42,23,52,33,46; (C) 46,34,42,23,52,33; (D) 42,46,33,23,34,52.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Simulate option C: 46 hashes to slot 6, 34 to 4, 42 to 2, and 23 to 3. Then 52 starts at 2 and probes occupied slots 2,3,4, stopping at 5. Finally 33 starts at 3 and probes occupied slots 3,4,5,6, stopping at 7. This exactly reproduces the figure. In A, 52 is inserted before 23 and takes slot 3; in B, 33 is inserted before 46 and takes slot 6; in D, 33 takes slot 3 before 23. Those disagree with the shown table, leaving C.

Linear probing tests h(k),h(k)+1,… modulo ten until an empty slot is reached. This means final position depends on insertion order, not only on the hash value. In the valid order, the four home-slot keys 42,23,34,46 establish the required occupied run before the displaced keys arrive. Neither 52 nor 33 wraps around the table in this instance.

Original paper, page 13

2 marks · MCQ
Report issue

Count insertion sequences for a hash table

Hashing

Question 53, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. How many distinct insertion permutations of these six keys produce this table?
Options: (A) 10; (B) 20; (C) 30; (D) 40.
Question 53, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. How many distinct insertion permutations of these six keys produce this table?
Options: (A) 10; (B) 20; (C) 30; (D) 40.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

For 52 to reach slot 5, the final occupants 42,23,34 of slots 2,3,4 must already be present. For 33 to reach slot 7, occupants 23,34,52,46 of slots 3,4,5,6 must already be present. Together these constraints make 33 last, and require 42,23,34 before 52; 46 can be anywhere among the first five. Among permutations of the first five keys, 52 must be last among {42,23,34,52}, which happens in 1/4 of the 5! orders. Thus 5!/4=30, option C. These constraints are sufficient because the home-slot keys then occupy their intended slots. Exhaustive simulation of all 720 permutations independently yields 30.

A second count inserts 46 into a sequence containing the other five keys. The first three among those five are 42,23,34 in any of 3! orders, followed by 52 and then 33. The 46 key may be inserted in any of the five gaps before 33, giving 3!×5=30. Inserting it after 33 would allow 33 to occupy slot 6 instead of 7.

Original paper, page 13

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

2 marks · MCQ
Report issue

Closed hashing with implicit linear probing

Hashing

Question 40, GATE 2007: An initially empty hash table has seven slots indexed 0–6 and h(x)=(3x+4) mod 7. Insert 1,3,8,10 in that order using “closed hashing” as stated in the source. Which final table is intended? A dash means an empty slot. The probing rule is not explicitly specified.
Options:
(A) [8,−,−,−,−,−,10]
(B) [1,8,10,−,−,−,3]
(C) [1,−,−,−,−,−,3]
(D) [1,10,8,−,−,−,3]
Tap to enlarge
Your answer
Answer & solution

Answer: B under linear probing (no official key was published)

1. Approach. Under linear probing, collisions advance one slot at a time with wraparound modulo 7. Compute each home position before inserting and never overwrite an occupied slot.

2. Derivation and interpretation. The hash values for 1,3,8,10 are 0,6,0,6. With linear probing, place 1 at 0 and 3 at 6;8 probes from 0 to 1;10 probes 6,0,1 and lands at 2. The table is [1,8,10,empty,empty,empty,3], B. Closed hashing/open addressing does not alone specify the probing sequence; quadratic or double hashing could differ, so linear probing is an explicit assumption rather than a stated guarantee.

Original paper, page 9

1 mark · MCQ
Report issue

Hash collisions under modulo ten

Hashing

Question 7, GATE 2004: Hash the input 4322,1334,1471,9679,1989,6171,6173,4199 using h(x)=x mod 10. Which statements hold? (1) 9679,1989,4199 collide. (2) 1471,6171 collide. (3) All inputs hash to the same value. (4) Every input has a different hash value.
Options:
(A) 1 only
(B) 2 only
(C) 1 and 2 only
(D) 3 or 4
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. The hash is the last decimal digit.9679,1989,4199 all map to 9, while 1471 and 6171 both map to 1. The remaining values map to 2,4,3.

2. Thus statements 1 and 2 only are true, C.

3. Teaching check: The eight hash values in input order are 2,4,1,9,9,1,3,9. This explicit list both verifies the two claimed collisions and refutes the “all equal” and “all different” alternatives. Collision means equal hash output, not equal original keys.

Original paper, page 1

1 mark · MCQ
Report issue

Deletion with hash chaining

Hashing

Question 1.13, GATE 1996: Why can separate chaining be preferable to open addressing: better worst-case search, less storage, easier deletion, or another claim?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

In chaining, keys in a bucket form a separate collection. Once the key and necessary predecessor are found, deletion simply unlinks it without changing the search path for other keys. In open addressing, clearing a slot outright may incorrectly terminate a later probe, so deletion needs tombstones or careful reorganization. Both approaches can have linear worst-case search, and chaining normally incurs pointer or container overhead. The reliable advantage among these claims is therefore easier deletion, C, rather than a universal space or worst-case-time improvement.

Original paper, page 2

Descriptive
Report issue

Identify linear-probing collisions

Hashing

Question 15(a), GATE 1996: Insert K,R,P,C,S,N,Y,T,J,M in that order into slots 0,…,9 using linear probing and h(x)=(ord(x)−ord('a')+1) mod10. The input is uppercase while the formula uses lowercase a; distinguish alphabet-position normalization from literal uppercase ASCII. Which insertions collide?
Question 15(a), GATE 1996: Insert K,R,P,C,S,N,Y,T,J,M in that order into slots 0,…,9 using linear probing and h(x)=(ord(x)−ord('a')+1) mod10. The input is uppercase while the formula uses lowercase a; distinguish alphabet-position normalization from literal uppercase ASCII. Which insertions collide?
Tap to enlarge
Answer & solution

Answer: J and M under either stated convention. (no official key was published)

With alphabet positions (equivalently lowercasing each character before applying the formula), the home slots are K1,R8,P6,C3,S9,N4,Y5,T0,J0,M3. The first eight insertions find empty slots. J collides at 0 with T and at 1 with K, then occupies 2. M collides at 3,4,5,6, occupied respectively by C,N,Y,P, then occupies 7. Thus J and M are exactly the insertions that encounter collisions.

The final normalized table is 0:T,1:K,2:J,3:C,4:N,5:Y,6:P,7:M,8:R,9:S. Every character appears once and all ten slots are filled.

For literal uppercase ASCII with the printed lowercase 'a', ord(uppercase)=ord(lowercase)−32. Therefore each home slot is shifted by −32≡−2 modulo 10. Linear probing is circular and the whole table rotates by the same amount. Homes become 9,6,4,1,7,2,3,8,8,1, and the final table is 0:J,1:C,2:N,3:Y,4:P,5:M,6:R,7:S,8:T,9:K. J and M still collide. This literal result uses mathematical nonnegative modulo; a language whose remainder operator returns negative values needs normalization before indexing. Neither the paper resolves the case/encoding convention, so both answers are disclosed rather than silently changing the formula.

Original paper, page 9

Descriptive
Report issue

Build the linear-probing table

Hashing

Question 15(b), GATE 1996: Insert K,R,P,C,S,N,Y,T,J,M in that order into slots 0,…,9 using linear probing and h(x)=(ord(x)−ord('a')+1) mod10. The input is uppercase while the formula uses lowercase a; distinguish alphabet-position normalization from literal uppercase ASCII. Give the final table.
Question 15(b), GATE 1996: Insert K,R,P,C,S,N,Y,T,J,M in that order into slots 0,…,9 using linear probing and h(x)=(ord(x)−ord('a')+1) mod10. The input is uppercase while the formula uses lowercase a; distinguish alphabet-position normalization from literal uppercase ASCII. Give the final table.
Tap to enlarge
Answer & solution

Answer: Alphabet positions: [T,K,J,C,N,Y,P,M,R,S]. Literal uppercase ASCII: [J,C,N,Y,P,M,R,S,T,K]. (no official key was published)

With alphabet positions (equivalently lowercasing each character before applying the formula), the home slots are K1,R8,P6,C3,S9,N4,Y5,T0,J0,M3. The first eight insertions find empty slots. J collides at 0 with T and at 1 with K, then occupies 2. M collides at 3,4,5,6, occupied respectively by C,N,Y,P, then occupies 7. Thus J and M are exactly the insertions that encounter collisions.

The final normalized table is 0:T,1:K,2:J,3:C,4:N,5:Y,6:P,7:M,8:R,9:S. Every character appears once and all ten slots are filled.

For literal uppercase ASCII with the printed lowercase 'a', ord(uppercase)=ord(lowercase)−32. Therefore each home slot is shifted by −32≡−2 modulo 10. Linear probing is circular and the whole table rotates by the same amount. Homes become 9,6,4,1,7,2,3,8,8,1, and the final table is 0:J,1:C,2:N,3:Y,4:P,5:M,6:R,7:S,8:T,9:K. J and M still collide. This literal result uses mathematical nonnegative modulo; a language whose remainder operator returns negative values needs normalization before indexing. Neither the paper resolves the case/encoding convention, so both answers are disclosed rather than silently changing the formula.

Original paper, page 9