0% found this document useful (0 votes)
4 views5 pages

Graph & Hashing _ DPP 01

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Graph & Hashing _ DPP 01

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

GATE

Data Structures & Programming


DPP: 1
CS & IT
Graph & Hashing

Ql 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) mod 10 and linear probing to resolve
Q4 Consider a hash table with 50 slots. Collisions
collisions.
are resolved using chaining. Assuming simple
Which insertions cause collisions?
uniform hashing, what is the probability that
(A} J (B} C
the first 3 slots are unfilled after the first 3
(C} M (D) p
insertions?
Q2 Consider a hash table with n buckets, where (A)(47 x 47 x 47)/503
external (overflow) chaining is used to resolve (B)(49 x 48 x 47)/503
collisions. The hash function is such that the (C)(47 x 46 x 45)/50 3
probability that a key value is hashed to a (D)(47 x 46 x 45)/(3! x 503)
particular bucket is ¾ .The hash table is initially QS Figure out true and false statements from
empty and K distinct values are inserted in the
below.
table. What's the probability that bucket
(A)Clusters formed by quadratic probing [open
number 1 is empty after the k insertion?
(A) (n-ll addressing] is called primary cluster.
nk (B)The worst case timing for successful and
(B} (n-ll-1
nk-1
unsuccessful search in separate chaining is
(C} (n-1) 0(1 + a) (where a is average chain length)
(C) Primary clusters degrade the hash table
(DJ_!_
nk
performance.
Q3 Consider a hash table of size seven, with (D)Some insertion may cycle through the list in
starting index zero, and a hash function (3x + 4) quadratic probing
mod 7. Assuming the hash table is initially
Q6 A hash table of length 10 uses open addressing
empty, which of the following is the contents of
with hash function h(k)=k mod 10, and linear
the table when the sequence 8, 10, 15, 17 is
probing. After inserting 8 values into an empty
inserted into the table using closed hashing?
hash table,the table is as shown below
Note that - denotes an empty location in the
table. 0 10
(A)15,-,-,-,-,-,17 1 21
(B} 8,15,17, -, -, -,10
2 32
(C)8,-,-,-,-,-,10
(D)8,17,15, -, -, -,10 3 43

CUSTOMER
SlflVKE
Android AP-P- I iOS AP-P- I PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=9mvzuzwi6rcse6I7xzzfd2joq 1/6
GATE

4 54 Q7 A hash table contains 9 buckets and uses linear


probing to resolve collisions. The key values are
5 65
integers and the hash function used is key % 9. If
6 76 the values 41, 157, 72, 76, 31 are inserted in the

7 77 table, in what location would the last key be


inserted? _________________
8
QS Consider a hash table with 11 slots. The hash
9
function is h(k) = k mod 11. The collisions are
How many different insertion sequences
resolved by chaining. The following 11 keys are
possible using the same hash function and
inserted in the order: 28, 19, 15, 20, 33, 30, 42, 63,
linear probing will result in the hash table shown
60, 32, 43. The maximum, minimum, and
above?
average chain lengths in the hash table,
(A)7!(factorial) (8)8!(factorial)
respectively, are-
(C) 8 (D) 1
(A) 3,0, 1 (8)3,3,3
(C)3,0,2 (D) 4,0,1

CUSTOMER
SlflVKE
Android AP-P- I iOS AP-P- I PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=9mvzuzwi6rcse6I7xzzfd2joq 2/6
GATE

Answer Key
Ql (A, C) QS (B, C, D)
Q2 (A) Q6 (B)
Q3 (B) Q7 7-7
Q4 (A) QS (A)

CUSTOMER
SlflVKE
Android AP-P- I iOS AP-P- I PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=9mvzuzwi6rcse6I7xzzfd2joq 3/6
GATE

Hints & Solutions


Ql Text Solution: Q2 Text Solution:
h(x) ((ord(x) - ord(A)) + 1) mod 10
= Probability that buckets other than 1 are
n-1
h(K) = ((ord(K) - ord(A)) + 1) mod 10 = ((11 - 1) + 1) selected = �
mod 10 = 1 this should happen k times and each of
h(R) = ((ord(R) - ord(A)) + 1) mod 10 = ((18 - 1) + 1) (n-ll
the k events are independent so--.kn
mod 10=8
h(P) = ((ord(P) - ord(A)) + 1) mod 10 = ((16 - 1) + 1) Q3 Text Solution:

mod 10=6 8 will occupy location 0, 10 will occupy


h(C) = ((ord(C) - ord(A)) + 1) mod 10 = ((3 - 1) + 1) location 6, 15 hashed to location 0 which is
mod 10=3 already occupied so, it will be hashed to one
h(S) = ((ord(S) - ord(A)) + 1) mod 10 =((19 - 1) + 1) location next to it. i.e. to location 1.
mod 10=9 Since 17 also clashes, so it will be hashed to
h(N) = ((ord(N) - ord(A)) + 1) mod 10 = ((14 - 1) + 1) location 2.
mod 10=4 Q4 Text Solution:
h(Y) = ((ord(Y) - ord(A)) + 1) mod 10 =((25 - 1) + 1) We have 100 slots each of which are picked
mod 10=5 with equal probability by the hash function
h(T) = ((ord(T) - ord(A)) + 1) mod 10 =((20 - 1) + 1) (since hashing is uniform). So, to avoid first 3
modl0=0 slots, the hash function has to pick from the
h(J) = ((ord(J) - ord(A)) + 1) mod 10 =((10 - 1) + 1) remaining 47 slots. And repetition is allowed,
modl0=0 since chaining is used- meaning a list of
h(M) = ((ord(M) - ord(A)) + 1) mod 10 =((13 - 1) + 1) elements are stored in a slot and not a single
mod 10=3 element.
0 T
So, required probability = 47/50x47/50x47/50
1 K
2 J =(47x47x47)/ 40 3
3 C QS Text Solution:

4 N A is false they are called secondary cluster


Bis TRUE
5 y
NOTATION: a = n/m = load factor
6 p (A) MATHEMATICAL PROOF

7 M (1) Assume that a new element is inserted at


the end of the linked list
8 R (2) Upon insertion of the i-th element, the
9 S expected length of the list is (i -1)/m
J and M are causing the collision.

CUSTOMER
SlflVKE
Android AP-P- I iOS AP-P- I PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=9mvzuzwi6rcse6I7xzzfd2joq 4/6
GATE

(3 ) In case of a successful search, the expected 60 mod 11 = 5


number of elements examined is 1 more that 32 mod 11 = 10
the number of elements examined when 43 mod 11 = 10
the sought-for element was inserted. Maximum chain length = 3
.!n ��
L..,1=1 (1 + i-1)
m
= 1 + _1 �� (i - 1)
nm L..,1=1
Minimum chain length = 0
Average chain length = 11/11 = 1
_
- + l 1 (n-l)n
nm ._2_
= + 1 n-1
2m
=1+..E....-_1
2m
_
2m
1+�--12
_
2m
C is TRUE
Dis TRUE

Q6 Text Solution:
Since all elements are in correct position you
can insert them in any order
Hence we can insert them in any order 8!
( factorial).

Q7 Text Solution:
41 mod 9 =5
157 mod 9 = 4
72 mod 9 = 0
76 mod 9 = 4
Since 157 occupies 4 and 41 occupies 5, 76 is
hashed to 6
31 mod 9 = 4
Since 157 occupies 4, 41 occupies 5, 76 occupies
6, 31 is hashed to 7

Q8 Text Solution:
28 mod 11 = 6
19 mod 11 = 8
15 mod 11 = 4
20 mod 11 = 9
33 mod 11 = 0
30 mod 11 = 8
42 mod 11 = 9
63 mod 11 = 8

CUSTOMER
SlflVKE
Android AP-P- I iOS AP-P- I PW Website

https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf?session_id=9mvzuzwi6rcse6I7xzzfd2joq 5/6

You might also like