Consider a 13 element hash table for which f(key)=key mod 13 is used with…

2014

Consider a 13 element hash table for which f(key)=key mod 13 is used with integer keys. Assuming linear probing is used for collision resolution, at which location would the key 103 be inserted, if the keys 661, 182, 24 and 103 are inserted in that order?

Answer: B. 1The hash table size is 13, so indices range from 0 to 12. The hash function is f(key) = key mod 13. Insert 661: 661 % 13 = 11. Index 11 is empty, so place 661…

  1. A.

    0

  2. B.

    1

  3. C.

    11

  4. D.

    12

Attempted by 328 students.

Show answer & explanation

Correct answer: B

The hash table size is 13, so indices range from 0 to 12. The hash function is f(key) = key mod 13.

Insert 661: 661 % 13 = 11. Index 11 is empty, so place 661 at index 11.

Insert 182: 182 % 13 = 0. Index 0 is empty, so place 182 at index 0.

Insert 24: 24 % 13 = 11. Index 11 is occupied by 661. Probe to index 12, which is empty. Place 24 at index 12.

Insert 103: 103 % 13 = 12. Index 12 is occupied by 24. Probe to index 0, which is occupied by 182. Probe to index 1, which is empty. Place 103 at index 1.

Thus, key 103 is inserted at location 1.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…