Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Insert the characters of the string K R P C S... Start Learning for Free
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
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Insert the characters of the string K R P C S N Y T J M into a hash ta...
(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
View all questions of this test
Most Upvoted Answer
Insert the characters of the string K R P C S N Y T J M into a hash ta...
- 65 ) % 10.

First, we need to calculate the hash value for each character using the given hash function:

- h(K) = (ord(K) - 65) % 10 = (75 - 65) % 10 = 1
- h(R) = (ord(R) - 65) % 10 = (82 - 65) % 10 = 7
- h(P) = (ord(P) - 65) % 10 = (80 - 65) % 10 = 5
- h(C) = (ord(C) - 65) % 10 = (67 - 65) % 10 = 2
- h(S) = (ord(S) - 65) % 10 = (83 - 65) % 10 = 8
- h(N) = (ord(N) - 65) % 10 = (78 - 65) % 10 = 3
- h(Y) = (ord(Y) - 65) % 10 = (89 - 65) % 10 = 4
- h(T) = (ord(T) - 65) % 10 = (84 - 65) % 10 = 9
- h(J) = (ord(J) - 65) % 10 = (74 - 65) % 10 = 0
- h(M) = (ord(M) - 65) % 10 = (77 - 65) % 10 = 2

Note that we subtracted 65 from the ASCII code of each character to get a value between 0 and 25, which is then modulo 10 to get a value between 0 and 9.

Next, we can insert each character into the hash table based on its hash value:

Index | Hash value | Character
------|-----------|----------
0 | 0 | J
1 | 1 | K
2 | 2 | C
3 | 3 | N
4 | 4 | Y
5 | 5 | P
6 | - |
7 | 7 | R
8 | 8 | S
9 | 9 | T

We can see that the characters with the same hash value (C and M) are stored in the same slot of the hash table using separate chaining, which means that each slot contains a linked list of elements that have the same hash value. In this case, the slot at index 2 contains both C and M.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer?
Question Description
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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer?.
Solutions for 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice 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 functionh(x) = ( ord(x) – ord("a") + 1 ) mod10If linear probing is used to resolve collisions, then the following insertion causes collisiona)Yb)Cc)Md)PCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev