Skip to content
Related Articles

Related Articles

Data Structures | Hash | Question 4
  • Difficulty Level : Basic
  • Last Updated : 25 Oct, 2018
GeeksforGeeks - Summer Carnival Banner

Consider a hash table of size seven, with starting index zero, and a hash function (3x + 4)mod7. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing? Note that ‘_’ denotes an empty location in the table.
(A) 8, _, _, _, _, _, 10
(B) 1, 8, 10, _, _, _, 3
(C) 1, _, _, _, _, _,3
(D) 1, 10, 8, _, _, _, 3


Answer: (B)

Explanation: Please see http://lcm.csa.iisc.ernet.in/dsa/node38.html for closed hashing and probing.

Let us put values 1, 3, 8, 10 in the hash of size 7.

Initially, hash table is empty

    -    -    -   -   -   -   -
    0    1   2   3   4   5   6

The value of function (3x + 4)mod 7 for 1 is 0, so let us put the value at 0

    1    -    -   -   -   -   -
    0    1   2   3   4   5   6

The value of function (3x + 4)mod 7 for 3 is 6, so let us put the value at 6



    1    -    -   -   -   -   3
    0    1   2   3   4   5   6

The value of function (3x + 4)mod 7 for 8 is 0, but 0 is already occupied, let us put the value(8) at next available space(1)

    1    8    -   -   -   -   3
    0    1   2   3   4   5   6

The value of function (3x + 4)mod 7 for 10 is 6, but 6 is already occupied, let us put the value(10) at next available space(2)

    1    8   10   -   -   -   3
    0    1   2    3   4   5   6

 

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :