• edited by
3,686 views
2 2 votes

Consider a hash table consisting of M=11 slots, and suppose integer key value are hashed into the table using hash function h1:

int h1(int key)
{
    x = (key + 5)*(key + 5);
    x = x/6;
    x = x + key;
    x = x%11;
    return x;
}

Suppose that collisions are resolved using linear probing. The probe in sequence is given therefore by

h1(k) + i(mod)11

The integer key values listed below are to be inserted, in the order given below. What are the final contents of the hash table after the following key values have been inserted in the given order:
43, 23, 1, 0, 15, 31, 4, 7, 11, 3

Source:- http://www.techtud.com/example/hashing

3 Answers

1 1 vote

Answer is D.

option C : 1st 4 elements are going to right place but just don’t blindly conclude, you will have to try all elements.

15 is not hashed to 1st place. :) . So Option C is wrong.

0 0 votes
answer is c
0 0 votes

Ans - C)

Take small value first. Lets take 0, Pass Key =  0 in program.

  1. X = garbage
  2. X = ( 0 + 5 )*(0 + 5) = 25
  3. X = 25/16 = 1(only integer part because x is integer)
  4. X = 1 + 0 = 1
  5. X = 1 % 11 = 1
  6. Return 1
  7. So put h1(k) = 1.
  8. ( 1 + 0 ) mod11 = 1 so update the index position 1 = 0

Repeat same for all, you'll get (c) as answer.

Note : i ranges from {0,1,2,.......,(M-1)}. So if any collision detected increase the i value.

 

• edited by
Position:
Show:

Related questions

60 60 votes
4 answers 4 answers
25.1k
25.1k views
Arjun asked Feb 12, 2020
25,118 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...
2 2 votes
1 1 answer
1.8k
1.8k views
Hradesh patel asked Oct 1, 2016
1,811 views
Let $| U | = m^{2}$ and consider hashing with chaining. For any hash function $h : U\rightarrow{ 1, 2, ......., m-1}, $ there exists a sequence of $m$ insertions that lea...
1 1 vote
2 answers 2 answers
948
948 views
0 0 votes
1 1 answer
861
861 views