# GATE | GATE CS 1996 | Question 63

Insert the characters of the string K R P C S N Y T J M into a hash table of size 10.
Use the hash function

`h(x) = ( ord(x) – ord("a") + 1 ) mod10`

If linear probing is used to resolve collisions, then the following insertion causes collision
(A) Y
(B) C
(C) M
(D) P

Explanation:
(a) The hash table with size 10 will have index from 0 to 9.
hash function = h(x) = ((ord(x) – ord(A) + 1)) mod 10
So for string K R P C S N Y T J M:
K will be inserted at index : (11-1+1) mod 10 = 1
R at index: (18-1+1) mod 10 = 8
P at index: (16-1+1) mod 10 = 6
C at index: (3-1+1) mod 10 = 3
S at index: (19-1+1) mod 10 = 9
N at index: (14-1+1) mod 10 = 4
Y at index (25-1+1) mod 10 = 5
T at index (20-1+1) mod 10 = 0
J at index (10-1+1) mod 10 = 0 // first collision occurs.
M at index (13-1+1) mod 10 = 3 //second collision occurs.

Only J and M are causing the collision.

(b) Final Hash table will be:

```0    T
1    K
2    J
3    C
4    N
5    Y
6    P
7    M
8    R
9    S```

My Personal Notes arrow_drop_up

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.