Consider a hash table with slots. The hash function is . The collisions are resolved by chaining. The following keys are inserted in the order: . The maximum, minimum, and average chain lengths in the hash table, respectively, are
View worked solution
Answer: A
To find the maximum, minimum, and average chain lengths, we map each key to its corresponding slot in the hash table of size using the hash function .
Let's compute the slot index for each key in the order of insertion:
Now, we group the keys into their respective slots (chains):
- Slot 0: Empty (Chain length = )
- Slot 1: (Chain length = )
- Slot 2: (Chain length = )
- Slot 3: (Chain length = )
- Slot 4: Empty (Chain length = )
- Slot 5: (Chain length = )
- Slot 6: (Chain length = )
- Slot 7: Empty (Chain length = )
- Slot 8: (Chain length = )
From the slot distribution, we can determine the required metrics:
- Maximum chain length: The longest chain is at Slot 1, which has a length of .
- Minimum chain length: Slots 0, 4, and 7 are empty, so the minimum chain length is .
- Average chain length:
Thus, the maximum, minimum, and average chain lengths are and respectively.
Free practice · Your answers on this page are not saved.
