edited by
10,286 views
34 votes
34 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$
edited by

3 Answers

Best answer
48 votes
48 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 votes
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
Answer:

Related questions

90 votes
90 votes
11 answers
2
go_editor asked Sep 26, 2014
24,561 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...