A hash table of length uses open addressing with hash function , and linear probing. After inserting values into an empty hash table, the table is shown as below
How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?
View worked solution
Answer: C
To find the number of valid insertion sequences, we analyze the dependencies between the keys based on their hash values and their final positions in the table:
- 42 (): Placed at index 2. No dependencies.
- 23 (): Placed at index 3. No dependencies.
- 34 (): Placed at index 4. No dependencies.
- 46 (): Placed at index 6. No dependencies.
- 52 (): Placed at index 5. For to probe and land at index 5, indices 2, 3, and 4 must already be occupied. Thus, 42, 23, and 34 must be inserted before 52.
- 33 (): Placed at index 7. For to probe and land at index 7, indices 3, 4, 5, and 6 must already be occupied. Thus, 23, 34, 52, and 46 must be inserted before 33.
Combining these constraints, we get the following partial order (poset) on the 6 keys:
Since all other 5 elements must be inserted before , must be at the very last position (position 6) of any valid insertion sequence.
For the remaining 5 elements , the only constraint is that and must precede .
- The total number of permutations of these 5 elements is .
- Among the 4 elements , must appear last. The probability of being the last among these 4 elements in a random permutation is .
Therefore, the number of valid insertion sequences is:
Free practice · Your answers on this page are not saved.
