edited by
16,492 views
50 50 votes

Consider a hash table with $9$ slots. The hash function is $h(k)= k \mod 9$. The collisions are resolved by chaining. The following $9$ keys are inserted in the order: $5, 28, 19, 15, 20, 33, 12, 17, 10$. The maximum, minimum, and average chain lengths in the hash table, respectively, are

  1. $3, 0,$ and $1$
  2. $3, 3,$ and $3$
  3. $4, 0,$ and $1$
  4. $3, 0,$ and $2$

5 Answers

Best answer
67 67 votes

So, Maximum & minimum chain lengths are $3  \ \&  \ 0$ respectively.

Average chain length $= (0+3+1+1+0+1+2+0+1)/9 = 1$ .

So, Answer is A.

edited by
3 3 votes
Following are values of hash function for all keys

 5 --> 5
28 --> 1
19 --> 1  [Chained with 28]
15 --> 6
20 --> 2
33 --> 6  [Chained with 15]
12 --> 3
17 --> 8
10 --> 1 [Chained with 28 and 19]

The maximum chain length is 3. The keys 28, 19 and 10 go to same slot 1, and form a chain of length 3. The minimum chain length 0, there are empty slots (0, 4 and 7). Average chain length is (0 + 3 + 1 + 1 + 0 + 1 + 2 + 0 + 1)/9 = 1
0 0 votes
Here's another way to look at it,
The expected length of the linked list in chaining is $\alpha=\frac{n}{m}$ where $n$ is the number of keys and $m$ is the size of hash table. So here $n=9$ and $m=9$ which makes the average size as $1$. As for the maximum size it's apparent that $28,19,10$ all the three have $1$ modulo 10 as the highest length of linked list. So option $(A)$ is the answer
0 0 votes
avg is  sum of all 0+3+1+1+0+1+2+0+1=9

9/9=1 avg

max = 3

min 0
Answer:
Position:
Show:

Related questions

78 78 votes
11 answers 11 answers
33.3k
33.3k views
go_editor asked Sep 28, 2014
33,324 views
Consider a $6$-stage instruction pipeline, where all stages are perfectly balanced. Assume that there is no cycle-time overhead of pipelining. When an application is exec...
59 59 votes
4 answers 4 answers
24.9k
24.9k views
Arjun asked Feb 12, 2020
24,903 views
Consider a double hashing scheme in which the primary hash function is $h_1(k)= k \text{ mod } 23$, and the secondary hash function is $h_2(k)=1+(k \text{ mod } 19)$. Ass...
139 139 votes
17 answers 17 answers
41.0k
41.0k views
go_editor asked Sep 26, 2014
40,953 views
Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of subtrees having exactly $4$ nodes is...
77 77 votes
5 answers 5 answers
32.0k
32.0k views
go_editor asked Sep 28, 2014
31,995 views
Consider a hash table with $100$ slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first $3$ slots are unfi...