edited by
3,319 views
1 votes
1 votes

The characters of the string $\text{K R P C S N Y T J M}$ are inserted into a hash table of the size of size $10$ using a hash function
$h(x)=(ord(x)-ord(A)+1)$ $mod$ $10$

If linear probing is used to resolve collisions, then the following insertion causes the collision

  1. $Y$
  2. $C$
  3. $M$
  4. $P$
edited by

2 Answers

5 votes
5 votes

$A \rightarrow 1$

$B \rightarrow 2$

$C \rightarrow 3$

$D \rightarrow 4$

$E \rightarrow 5$

$F \rightarrow 6$

$G \rightarrow 7$

$H \rightarrow 8$

$I \rightarrow 9$

$J \rightarrow 10$

$K \rightarrow 11$

$L \rightarrow 12$

$M \rightarrow 13$

$N \rightarrow 14$

$O \rightarrow 15$

$P \rightarrow 16$

$Q \rightarrow 17$

$R \rightarrow 18$

$S \rightarrow 19$

$T \rightarrow 20$

$U \rightarrow 21$

$V \rightarrow 22$

$W \rightarrow 23$

$X \rightarrow 24$

$Y\rightarrow 25$

$Z \rightarrow 26$

$h(x)= ( ( ord(x) - ord(A) ) + 1 ) \mod\ 10 $

$h(K)= ( ( ord(K) - ord(A) ) + 1 ) \mod\ 10  = ( (11 - 1 ) + 1) \mod\ 10 = 1$

$h(R)= ( ( ord(R) - ord(A) ) + 1 ) \mod\ 10  = ( (18 - 1 ) + 1) \mod\ 10 = 8$

$h(P)= ( ( ord(P) - ord(A) ) + 1 ) \mod\ 10  = ( (16 - 1 ) + 1) \mod\ 10 = 6$

$h(C)= ( ( ord(C) - ord(A) ) + 1 ) \mod\ 10  = ( (3 - 1 ) + 1) \mod\ 10 = 3$

$h(S)= ( ( ord(S) - ord(A) ) + 1 ) \mod\ 10  = ( (19 - 1 ) + 1) \mod\ 10 = 9$

$h(N)= ( ( ord(N) - ord(A) ) + 1 ) \mod\ 10  = ( (14 - 1 ) + 1) \mod\ 10 = 4$

$h(Y)= ( ( ord(Y) - ord(A) ) + 1 ) \mod\ 10  = ( (25 - 1 ) + 1) \mod\ 10 = 5$

$h(T)= ( ( ord(T) - ord(A) ) + 1 ) \mod\ 10  = ( (20 - 1 ) + 1) \mod\ 10 = 0$

$h(J)= ( ( ord(J) - ord(A) ) + 1 ) \mod\ 10  = ( (10 - 1 ) + 1) \mod\ 10 = 0$

$h(M)= ( ( ord(M) - ord(A) ) + 1 ) \mod\ 10  = ( (13 - 1 ) + 1) \mod\ 10 = 3$

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

J and M are causing the collision

The ord() method returns an integer representing the Unicode code point of the given Unicode character in python.

# code point of integer
print(ord('5'))

# code point of alphabet 
print(ord('A'))

# code point of character
print(ord('$'))


output:
53
65
36
0 votes
0 votes

Hash function h(x) = ((ord(x) – ord(A) + 1)) %10

Given string is K R P C S N Y T J M. Take alphabetic ordering of each character is worth saving time to solve these questions. Therefore,

K will be inserted at index (11-1+1)%10 = 1

R at index (18-1+1) %10 = 8

P at index (16-1+1) % 10 = 6

C at index (3-1+1) % 10 = 3

S at index (19-1+1) % 10 = 9

N at index (14-1+1) % 10 = 4

Y at index (25-1+1) %10 = 5

T at index (20-1+1) % 10 = 0

J at index (10-1+1) %10 = 0 (Ist collision occurs, because 0th index is already filled by T).

M at index (13-1+1) % 10 = 3 (2nd collision occurs, because 3rd index is already filled by C).

Only J and M causes 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
Answer:

Related questions

1 votes
1 votes
1 answer
1
gatecse asked Dec 17, 2017
1,832 views
Quick-sort is run on $2$ inputs shown below to sort in ascending order :$1,2,3\ldots n$$n,n-1,n-2\ldots 1$Let $C$1 and $C2$ be the number of comparisons made for A and B ...
3 votes
3 votes
2 answers
2
gatecse asked Dec 17, 2017
1,425 views
A sorting technique is called stable ifIf it takes $O(n\log n)$ time.It uses divide and conquer technique.Relative order of occurrence of non-distinct elements is maintai...
4 votes
4 votes
1 answer
3
gatecse asked Dec 17, 2017
1,709 views
Match the following and choose the correct answer for the order $A,B,C,D$$$\begin{array}{|ll|ll|}\hline \text{A.} & \text{Strassen matrix multiplication} & \text{p.} & ...
3 votes
3 votes
2 answers
4
gatecse asked Dec 17, 2017
3,015 views
Consider the recurrence equation$T(n) =\begin{cases}2T(n-1), & \text{if }n>0 \\1, & \text{otherwise}\end{cases}$Then $T(n)$ is (in $big\, O$ order)$O(n)$$O(2^n)$$O(1)$$O(...