Last Updated :
14 Nov, 2018
The characters of the string K R P C S N Y T J M are inserted into a hash table of size 10 using hash function
h(x) = ((ord(x) - ord(A) + 1)) mod 10
If linear probing is used to resolve collisions, then the following insertion causes collision
(A) Y
(B) C
(C) M
(D) P
Answer: (C)
Explanation: 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.
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
So, option (C) is correct.
Quiz of this Question
Share your thoughts in the comments
Please Login to comment...