1
CSE/IT Batch:Hinglish
Data Structure
Hashing DPP-01
[NAT] [NAT]
1. Consider a hash table H with 512 slots. If 128 keys 6. Consider a double hashing scheme in which the
areto be stored in H, the load factor of H is primary hash function is h1 (k) = k mod 17, and the
. secondary hash function is h2 (k) = 1 + (k mod 13).
Assume that the table size is 17. Then the
[NAT] addressreturned by probe 2 in the probe sequence
2. Consider a hash function that distributes keys (assume thatthe probe sequence begins at probe 0)
uniformly. The hash table size is 2024. After hashing for key value k
of how many keys will the probability that any new = 127 is .
key hashed collides with an existing one exceed 0.75?
___________ [MCQ]
7. Consider a hash table with 11 slots. The hash function
[MCQ] is h(k) = k mod 11. The collisions are resolved by
3. Suppose we are given n keys, m hash table slots, and chaining. The following 11 keys are inserted in the
two simple uniform hash functions h1 and h2. Further order: 28, 19, 15, 20, 33, 30, 42, 63, 60, 32, 43. The
suppose our hashing schemes uses h1 for the even keys maximum, minimum, and average chain lengths in the
and h2 for the odd keys. What is the expected number hash table, respectively, are-
of keys in a slot? (a) 3, 0, 1 (b) 3, 3, 3
n m (c) 3, 0, 2 (d) 4, 0, 1
(a) (b)
m n
2n m [MCQ]
(c) (d)
m 2n 8. A hash table of length 8 uses open addressing with
hashfunction h(k)= 2 + k mod 8, and linear probing.
[NAT] After inserting 5 values into an empty hash table, the
4. A hash table contains 9 buckets and uses linear table isas shown below.
probing to resolve collisions. The key values are 0
integers and the hash function used is key % 9. If 1
the values 41, 157, 72, 76, 31 are inserted in the 2 64
table, in what location would the last key be 3 41
inserted? _________________. 4 57
5 72
6
7 29
[MCQ]
5. Which one of the following hash functions on integers How many different insertion sequences of the key
will distribute keys most uniformly over 10 buckets values using the same hash function and linear
numbered 0 to 9 for i ranging from 0 to 2024? probingwill result in the hash table shown above?
(a) h(i) = (12 ∗ i) mod 10 (a) 10 (b) 9
(b) h(i) = (11 ∗ i2) mod 10 (c) 15 (d) 8
(c) h(i) =i3 mod 10
(d) h(i) =i2 mod 10
2
Answer Key
1. (0.25) 5. (c)
2. (1518) 6. (13)
3. (a) 7. (a)
4. (7) 8. (c)
3
Hints and Solutions
1. (0.25) 6. (13)
128 D-Hashing (k, probe) = (h1(k) + probe × h2(k))
Load factor =
512 mod m
Where, probe = 0 to m – 1
2. (1518) m = Number of empty slots in hash table)
Let x be the number of keys after which any new key
3 D-Hashing (127, 2) = (127 mod 17 + 2 × (1 + 127
hashed collides with an existing one exceed mod 13)) mod 17
4
1 3 = (8 + 2 × (1 + 10)) mod 17 = 13
x=
2024 4
7. (a)
x = 1518
28 mod 11 = 6
3. (a) 19 mod 11 = 8
If h1 is used for the even keys and h2 for the odd keys,
15 mod 11 = 4
the expected number of keys in a slot is still equivalent
20 mod 11 = 9
n
to
m 33 mod 11 = 0
30 mod 11 = 8
4. (7) 42 mod 11 = 9
41 mod 9 =5 63 mod 11 = 8
157 mod 9 = 4 60 mod 11 = 5
72 mod 9 = 0 32 mod 11 = 10
76 mod 9 = 4 43 mod 11 = 10
Since 157 occupies 4 and 41 occupies 5, 76 is hashed Maximum chain length = 3
to 6
Minimum chain length = 0
31 mod 9 = 4
Average chain length = 11/11 = 1
Since 157 occupies 4, 41 occupies 5, 76 occupies 6,
31 is hashed to 7
8. (c)
64 is hashed to 2.
5. (c)
41 is hashed to 3.
h(i) = i3 mod 10 will distribute keys most uniformly
57 is too hashed to 3. To avoid collision, 57 is
over 10 buckets numbered 0 to 9 for i ranging from 0 hashed in 4.
to 2024.
Similarly, 72 and 29 are also dependent.
4
Order: (i) 64 41 57 72
(i) 64 41 (ii) 41 64 After 29
5ways
57 single place 57 2 place
(ii) 41 57 64 72
After 57: (1) 64 41 57
5 ways
(2) 41 57 64
(3) 41 34 57 (iii) 41 64 57 72
(iii) 72. 5 ways
(i) 64 41 57 (ii) 41 57 64 (iii) 41 64 57 Total = 15 ways
72 1 way 1 way
1 way
After 72
Any issue with DPP, please report by clicking here:- https://forms.gle/t2SzQVvQcs638c4r5
For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if
PW Mobile APP: https://smart.link/7wwosivoicgd4