Question 16a
Given the values 72,13,6,5,10,36,43 and 17 and a hash table of size 11. Show the resultant table after inserting values in the given order by using hash function h(k)=k%11 with each of the following collision strategies. i) Linear Probing ii) Quadratic Probing iii) Separate Chaining
Topics: Collision resolution: linear probing, quadratic probing, double hashing, Open hashing (separate chaining)
Watch this exact question run
Other parts: Quadratic probingSeparate chaining
Solution
- Quadratic probing uses (h(k) + i²) mod 11, i = 0, 1, 2, …
- Separate chaining appends new keys at the end of the chain.
| Key | 72 | 13 | 6 | 5 | 10 | 36 | 43 | 17 |
|---|---|---|---|---|---|---|---|---|
| k mod 11 | 6 | 2 | 6 | 5 | 10 | 3 | 10 | 6 |
| Key | Home h(k) | Probes | Stored at |
|---|---|---|---|
| 72 | 6 | (6 + 0) mod 11 = 6 | 6 |
| 13 | 2 | (2 + 0) mod 11 = 2 | 2 |
| 6 | 6 | (6 + 0) mod 11 = 6 → (6 + 1) mod 11 = 7 | 7 |
| 5 | 5 | (5 + 0) mod 11 = 5 | 5 |
| 10 | 10 | (10 + 0) mod 11 = 10 | 10 |
| 36 | 3 | (3 + 0) mod 11 = 3 | 3 |
| 43 | 10 | (10 + 0) mod 11 = 10 → (10 + 1) mod 11 = 0 | 0 |
| 17 | 6 | (6 + 0) mod 11 = 6 → (6 + 1) mod 11 = 7 → (6 + 2) mod 11 = 8 | 8 |
Final table — 0: 43 | 1: — | 2: 13 | 3: 36 | 4: — | 5: 5 | 6: 72 | 7: 6 | 8: 17 | 9: — | 10: 10
| Key | Home h(k) | Probes | Stored at |
|---|---|---|---|
| 72 | 6 | (6 + 0²) mod 11 = 6 | 6 |
| 13 | 2 | (2 + 0²) mod 11 = 2 | 2 |
| 6 | 6 | (6 + 0²) mod 11 = 6 → (6 + 1²) mod 11 = 7 | 7 |
| 5 | 5 | (5 + 0²) mod 11 = 5 | 5 |
| 10 | 10 | (10 + 0²) mod 11 = 10 | 10 |
| 36 | 3 | (3 + 0²) mod 11 = 3 | 3 |
| 43 | 10 | (10 + 0²) mod 11 = 10 → (10 + 1²) mod 11 = 0 | 0 |
| 17 | 6 | (6 + 0²) mod 11 = 6 → (6 + 1²) mod 11 = 7 → (6 + 2²) mod 11 = 10 → (6 + 3²) mod 11 = 4 | 4 |
Final table — 0: 43 | 1: — | 2: 13 | 3: 36 | 4: 17 | 5: 5 | 6: 72 | 7: 6 | 8: — | 9: — | 10: 10
| Key | Home h(k) | Chain | Stored at |
|---|---|---|---|
| 72 | 6 | append | 6 |
| 13 | 2 | append | 2 |
| 6 | 6 | append | 6 |
| 5 | 5 | append | 5 |
| 10 | 10 | append | 10 |
| 36 | 3 | append | 3 |
| 43 | 10 | append | 10 |
| 17 | 6 | append | 6 |
Final table — 0: — | 1: — | 2: 13 | 3: 36 | 4: — | 5: 5 | 6: 72 → 6 → 17 | 7: — | 8: — | 9: — | 10: 10 → 43
How to write it in the exam
| Index | Linear | Quadratic | Chaining |
|---|---|---|---|
| 0 | 43 | 43 | — |
| 1 | — | — | — |
| 2 | 13 | 13 | 13 |
| 3 | 36 | 36 | 36 |
| 4 | — | 17 | — |
| 5 | 5 | 5 | 5 |
| 6 | 72 | 72 | 72 → 6 → 17 |
| 7 | 6 | 6 | — |
| 8 | 17 | — | — |
| 9 | — | — | — |
| 10 | 10 | 10 | 10 → 43 |
Key collisions: 6 (at 6 → 7), 43 (at 10 → wraps to 0), 17 (linear: 6, 7 → 8; quadratic: 6, 7, 10 → (6+9) mod 11 = 4).
How this answer was verified
- Hand computation
- tests/hashing-search.test.ts (exact tables)
- hashing_open_addressing.c and hashing_chaining.c differential tests