Use the hash function: h(element) = element % 11 to store the collection of numbers: [44, 121, 55, 33, 110, 77, 22, 66] in a hash table. Display the hash table created. Search if the values 11, 44, 88 and 121 are present in the hash table, and display the search results.
Hash Value Calculation:
Using the hash function h(element) = element % 11:
| Element | Calculation | Hash Value |
|---|---|---|
| 44 | 44 % 11 | 0 |
| 121 | 121 % 11 | 0 |
| 55 | 55 % 11 | 0 |
| 33 | 33 % 11 | 0 |
| 110 | 110 % 11 | 0 |
| 77 | 77 % 11 | 0 |
| 22 | 22 % 11 | 0 |
| 66 | 66 % 11 | 0 |
Hash Table Created:
All elements have hash value 0, causing collision at index 0. Since collision resolution is beyond scope, only the first element (44) can be stored at index 0.
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Value | 44 | None | None | None | None | None | None | None | None | None | None |
Search Results:
For each search value, we compute hash and check the position:
-
11: 11 % 11 = 0 → Check index 0 → Value is 44 11 → Not present
-
44: 44 % 11 = 0 → Check index 0 → Value is 44 = 44 → Present at position 0
-
88: 88 % 11 = 0 → Check index 0 → Value is 44 88 → Not present
-
121: 121 % 11 = 0 → Check index 0 → Value is 44 121 → Not present
Explanation
This question tests understanding of hash function application and collision. All given numbers (44, 121, 55, 33, 110, 77, 22, 66) are multiples of 11, so they all produce hash value 0. This creates a collision situation where multiple elements map to the same index. As per the textbook context, collision resolution methods are beyond scope, so only one element can occupy index 0. For searching, the same hash function is applied to compute the position, and the element at that position is compared with the search key.
Solution Steps
Step 1: Calculate hash values for all elements using h(element) = element % 11
Step 2: Observe that all elements produce hash value 0 (collision)
Step 3: Create hash table with first element at index 0, rest positions as None
Step 4: For each search value, compute hash and check corresponding position
Step 5: Compare element at computed position with search value and report result