GATE / CS ARCHIVE

GATE CSE 2010 / QUESTION 53

Count insertion sequences for a hash table

Data Structures · Hashing · Full GATE CSE 2010 paper

GATE 2010, Q53 2 marks · MCQ
Report issue

Hashing

Question 53, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. How many distinct insertion permutations of these six keys produce this table?
Options: (A) 10; (B) 20; (C) 30; (D) 40.
Question 53, GATE 2010: A hash table has length ten, hash function h(k)=k mod 10, open addressing and linear probing. After six insertions into the initially empty table, slots 2,3,4,5,6,7 contain 42,23,34,52,46,33 respectively; slots 0,1,8,9 are empty. How many distinct insertion permutations of these six keys produce this table?
Options: (A) 10; (B) 20; (C) 30; (D) 40.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

For 52 to reach slot 5, the final occupants 42,23,34 of slots 2,3,4 must already be present. For 33 to reach slot 7, occupants 23,34,52,46 of slots 3,4,5,6 must already be present. Together these constraints make 33 last, and require 42,23,34 before 52; 46 can be anywhere among the first five. Among permutations of the first five keys, 52 must be last among {42,23,34,52}, which happens in 1/4 of the 5! orders. Thus 5!/4=30, option C. These constraints are sufficient because the home-slot keys then occupy their intended slots. Exhaustive simulation of all 720 permutations independently yields 30.

A second count inserts 46 into a sequence containing the other five keys. The first three among those five are 42,23,34 in any of 3! orders, followed by 52 and then 33. The 46 key may be inserted in any of the five gaps before 33, giving 3!×5=30. Inserting it after 33 would allow 33 to occupy slot 6 instead of 7.

Original paper, page 13