recategorized
8,963 views
0 votes
0 votes

A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed from 0 to 6. What will be the location of key 18?

  1. 3
  2. 4
  3. 5
  4. 6
recategorized

2 Answers

1 votes
1 votes
0 1 2 3 4 5 6
             

keys = 44,45,79,55,91,18,63

insert one by one, starts with 44

44%7 = 2

0 1 2 3 4 5 6
    44        

 

insert 45

45%7 = 3

0 1 2 3 4 5 6
    44 45      

 

insert 79

79%7 = 2 ---> collision===> check next cell, collision ===> check next cell ===> fit at 4

0 1 2 3 4 5 6
    44 45 79    

 

insert 55

55%7 = 6

0 1 2 3 4 5 6
    44 45 79   55

 

insert 91

91%7 = 0

0 1 2 3 4 5 6
91   44 45 79   55

 

insert 18

18%7 = 4  ---> collision===> check next cell ===> fit at 5

0 1 2 3 4 5 6
91   44 45 79 18 55

 

Therefore 18 fits at location 5

1 votes
1 votes

As per given hash function , we insert the keys and obtain the following table :  

Index Keys
0 91
1 63
2 44
3 45
4 79
5 18
6 55

18 will be stored at index 5

Related questions

1 votes
1 votes
3 answers
2
Pooja Khatri asked Jul 13, 2018
3,443 views
Consider the array A=<4, 1, 3, 2, 16, 9, 10, 14, 8, 7>. After building heap from the array A, the depth of the heap and the right child of max-heap are ______ and _____ r...
0 votes
0 votes
2 answers
3
Pooja Khatri asked Jul 13, 2018
2,611 views
Which of the following algorithms solves the single-source shortest paths?Prim's algorithmFloys-Warshall algorithmJohnson's algorithmDijkstra's algorithm
0 votes
0 votes
8 answers
4