GATE GUIDE

Hashing Questions in GATE CSE: Probing, Load Factor and Traps

By MD ANISH AHAMADUpdated 30 Oct 20269 min read
Hashing Questions in GATE CSE: Probing, Load Factor and Traps

Hashing questions in GATE CSE are almost always the same exercise. A small table is printed, a hash function and a collision rule are stated, a key sequence is given, and you report the final contents, the slot of one key, or a probe count. Nothing here is deep. Marks are lost on wraparound, on the probe-counting convention, and on assuming the answer does not depend on the order the keys arrived in.

In this guide
  1. Key takeaways
  2. Where hashing sits in the paper
  3. The standard exercise, traced end to end
  4. Why insertion order matters
  5. Three probe sequences on one table
  6. Separate chaining and the load factor
  7. Expected probes, used rather than derived
  8. Deletion and tombstones
  9. The traps in one list
  10. How to practise

Key takeaways

Where hashing sits in the paper

Hashing is named verbatim in the Algorithms line of the official CS syllabus for 2027: searching, sorting, hashing. It is not a borderline topic, even though the table, the chains and the probe arithmetic are pure data structures work.

Third-party analyst compilations put Programming and Data Structures at 6 to 13 marks per paper from 2009 to 2026, averaging near 9.9 with a stable direction. Taken with Algorithms the block averages about 18 marks, the largest after mathematics and General Aptitude. The split moves every year, which is why the two are prepared as one unit: 2021 was 6 plus 11, while 2026 shift 1 was 9 plus 10. One analyst's count for 2026 shift 2 put Programming and Data Structures at 8 questions, the highest of any subject that shift. These figures are unofficial, the 2014 and 2015 values merge data structures with algorithms in the source, and analysts disagree by 2 to 3 marks on borderline questions. Check the current notification for the pattern that applies to your year.

Several concepts from the 2000 to 2005 papers have reappeared in near-identical form after 2015, and the probe sequence of a hash table is named as one of them. The full subject ranking sits in the Algorithms important topics guide, and the broader tracing patterns are in the guide to data structure question patterns.

The standard exercise, traced end to end

Take a table of size 7, slots 0 to 6, with h(k)=k mod 7h(k) = k \bmod 7 and linear probing. Insert 25, 12, 13, 6, 19 in that order.

Key h(k)h(k) Slots examined Lands in Probes
25 4 4 4 1
12 5 5 5 1
13 6 6 6 1
6 6 6, 0 0 2
19 5 5, 6, 0, 1 1 4

Final table: slot 0 holds 6, slot 1 holds 19, slots 2 and 3 are empty, 4 holds 25, 5 holds 12, 6 holds 13. Total probes across the five insertions: 9. Total collisions: 4.

Two things in that trace carry marks. Key 6 wrapped from slot 6 to slot 0 because 7 mod 7=07 \bmod 7 = 0, and candidates who write the sequence as 6, 7 without the modulo lose the question there. And key 19 cost four probes although only one other key hashed to its home slot, because 25, 12 and 13 had already merged into one run. That is primary clustering: separate home slots grow into a single block, and any key landing anywhere in the block walks its whole length.

Why insertion order matters

Reverse the order and insert 19, 13, 12, 6, 25 into an empty table of the same size. Now 19 takes slot 5 on its first probe, 13 takes slot 6, 12 collides at 5 and 6 and lands in slot 0, and you finish with a different table from the same key set.

With linear probing the set of occupied slots comes out the same whichever order you use, which is a useful check on your work. What changes is which key sits in which slot, and therefore the probe count for any individual key. A question asking for the slot of the last key, or the probes needed by one named key, is order-sensitive by construction. One asking only which slots are full is not. For quadratic probing and double hashing even the occupied set can change with the order.

Three probe sequences on one table

Return to the state after 25, 12, 13 and 6 are in place, and insert 19 by each rule. Its home slot 5 is occupied.

Scheme ii-th probe Sequence for key 19 Lands in Probes
Linear probing (h(k)+i) mod 7\big(h(k) + i\big) \bmod 7 5, 6, 0, 1 1 4
Quadratic probing (h(k)+i2) mod 7\big(h(k) + i^2\big) \bmod 7 5, 6, 2 2 3
Double hashing (h1(k)+i⋅h2(k)) mod 7\big(h_1(k) + i \cdot h_2(k)\big) \bmod 7 5, 3 3 2

Here h2(k)=1+(k mod 5)h_2(k) = 1 + (k \bmod 5), so:

h2(19)=1+(19 mod 5)=5second probe=(5+5) mod 7=3\begin{aligned} h_2(19) &= 1 + (19 \bmod 5) = 5 \\ \text{second probe} &= (5 + 5) \bmod 7 = 3 \end{aligned}

Same key, same table, three different answers. Read the stated rule before computing anything, because setters switch the quadratic form between i2i^2, c1i+c2i2c_1 i + c_2 i^2, and variants that alternate sign.

Three properties are worth memorising.

Separate chaining and the load factor

In separate chaining each slot holds a linked list and colliding keys are appended, so no key is ever displaced. The load factor α=n/m\alpha = n/m is the average chain length and is allowed to exceed 1: 150 keys in 100 slots gives α=150/100=1.5\alpha = 150/100 = 1.5, an average chain of one and a half nodes. Under open addressing α\alpha can never exceed 1, because each key occupies its own slot. The trade is a pointer per node against a table that degrades sharply as it fills.

Expected probes, used rather than derived

Under the simple uniform hashing assumption the closed forms below are all you need. You are never asked to derive them.

Scheme Unsuccessful search Successful search
Separate chaining 1+α1 + \alpha 1+α/21 + \alpha/2 approximately
Open addressing, uniform hashing 11−α\displaystyle \frac{1}{1 - \alpha} 1αln⁡11−α\displaystyle \frac{1}{\alpha} \ln \frac{1}{1 - \alpha}
Linear probing (approximation) 12(1+1(1−α)2)\displaystyle \frac{1}{2}\left(1 + \frac{1}{(1 - \alpha)^2}\right) 12(1+11−α)\displaystyle \frac{1}{2}\left(1 + \frac{1}{1 - \alpha}\right)

At α=0.5\alpha = 0.5 under uniform hashing an unsuccessful search costs 11−0.5=2\displaystyle \frac{1}{1 - 0.5} = 2 probes and a successful one 10.5ln⁡2≈1.39\displaystyle \frac{1}{0.5} \ln 2 \approx 1.39. At α=0.9\alpha = 0.9 the figures are 10 and about 2.56. The asymmetry is the whole point: an unsuccessful search must walk to an empty slot, while a successful one stops at a key inserted when the table was less full. Under linear probing that same α=0.9\alpha = 0.9 gives 12(1+10.12)=50.5\displaystyle \frac{1}{2}\left(1 + \frac{1}{0.1^2}\right) = 50.5 probes for an unsuccessful search, which is why the 1/(1−α)21/(1 - \alpha)^2 term matters. These belong on your formula sheet.

Deletion and tombstones

This is the part most candidates have never traced. In the final table above, delete 13 from slot 6 by blanking the cell, then search for 19. Its home slot 5 holds 12, so you move to slot 6, find it empty, and conclude 19 is absent, although 19 is sitting in slot 1. The delete silently broke the probe path.

The fix is a tombstone: mark the cell deleted rather than empty. A search treats a tombstone as occupied and keeps probing; an insertion treats it as free and may reuse it. Tombstones then accumulate, unsuccessful searches get slower even as the real key count falls, and the table needs periodic rehashing. In chaining none of this arises, because deleting a node from a list disturbs nothing else.

The traps in one list

The cross-subject version of this list is in common mistakes that cost marks in GATE CSE.

How to practise

Keep one table of size 7 or 11 and one key list of six to eight values, and run every scheme on it by hand: linear, quadratic, double hashing, then chaining. Write the probe sequence as an explicit list of slot numbers before deciding anything, and note the probe count for each insertion in a column as you go. Then delete one key from the middle of a run and search for a key behind it, so the tombstone problem becomes something you have seen rather than read about.

Then shuffle the same key list and redo it. Watching the same keys land in different slots fixes the order-dependence permanently. The Algorithms chapter of the GATE CSE 2027 book carries a full bank of these traces written out slot by slot, including the insertion-order counting variant this article only mentions.

Frequently asked questions

How many probes does it take to insert a key with linear probing?

Count every slot you examine, including the home slot. If the home slot h(k)h(k) is free the insertion costs one probe. If it is occupied you examine h(k)+1h(k) + 1, h(k)+2h(k) + 2 and so on modulo the table size, and each examined slot adds one more. Collisions are one fewer than probes, so read the question wording carefully before answering.

Why must the second hash function in double hashing never return zero?

The ii-th probe is (h1(k)+i⋅h2(k)) mod m\big(h_1(k) + i \cdot h_2(k)\big) \bmod m. If h2(k)h_2(k) is zero, every probe returns the same slot and the insertion loops forever on an occupied cell. That is why the standard form is 1 plus something mod a smaller number. It should also be coprime with mm so the sequence can reach every slot.

Can the load factor of a hash table be greater than 1?

With separate chaining, yes. The load factor is α=n/m\alpha = n/m, the average chain length, and nothing stops you from storing more keys than slots. With open addressing it cannot exceed one, because every key occupies a distinct slot and the table is full when n=mn = m. Exam questions exploit this difference.

Why is a deleted key replaced by a tombstone in open addressing?

A search stops at the first empty slot. If you simply blank a cell that lies on some other key's probe path, that key becomes unreachable even though it is still in the table. A tombstone marks the cell as deleted but not empty, so searches continue past it while insertions may reuse it.

What is the difference between primary and secondary clustering?

Primary clustering is the linear probing problem, where keys with different home slots merge into one long run, and any key hashing anywhere into that run makes it longer. Secondary clustering is milder and affects quadratic probing, where two keys with the same home slot follow exactly the same probe sequence and keep colliding.

Is hashing asked every year in GATE CSE?

Hashing is named verbatim in the Algorithms line of the CS syllabus, and the analyst reconstruction this guide uses places an open addressing item in roughly two thirds of recent shifts, usually a one or two mark numerical answer. That record makes it a high priority topic for 2027 without guaranteeing any particular question.

Sources

Dates, fees and the syllabus are set by the GATE 2027 organising institute and can change. Always confirm at gate2027.iitm.ac.in.

Keep reading

GATE CSE 2027 book1,020 pages · ₹250 ₹300
Buy now — ₹250