You are on page 1of 5

Advanced Data Structures- Assignment -1 Shubham Jain20001502012

Q1] Draw the 11-item hash table resulting from hashing the keys 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, and 5,
Ü

using the hash function h(i)=(2 i+ 5) mod 11 and assuming collisions are handled by chaining
l õ ÿR 􀀀 i
Q2] j What is the result of the previous exercise, assuming collisions are handled by linear probing?
Q3] Show the result of Q1, assuming collisions are handled by quadratic probing, up to the point where the
g

method fails because no empty slot is found.


Q4] jWhat is the result of Q1 assuming collisions are handled by double hashing using a secondary hash function
h’(k)= 7 – (k mod 7)
Q5] Give a pseudo-code description of an insertion into a hash table that uses quadratic probing to resolve
g

collisions, assuming we also use the trick of replacing deleted items with a special “deactivated item” object.

Ans 5. Pseudocode of Insertion into hash table

1. Get the key k

2. Set counter j = 0

3. Compute hash function h[k] = k % SIZE

4. If hashtable[h[k]] is empty or Deactivated item -> Insert key k at hashtable[h[k]] -> Stop

Else - The key space at hashtable[h[k]] is occupied, so we need to find the next available key space –

Increment j - Compute new hash function h[k].

h[k] = ( k + j * j ) % SIZE

Repeat Step 4 till j is equal to the SIZE of hash table

5. The hash table is full

6. Stop

You might also like