GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 15(b)

Build the linear-probing table

Data Structures · Hashing · Full GATE CSE 1996 paper

GATE 1996, Q15(b) Descriptive
Report issue

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