Model Question Paper (as circulated)Part B · Q15a4 marksCO4Module 4
Question 15a
You are given a hash table with 5 buckets (i.e., indices 0 to 4). Use open hashing (separate chaining) to insert the following set of keys: {12,42,22,52,32}. Use the division method in hashing.
Topics: Open hashing (separate chaining)
Watch this exact question run
Loading visualizer…
Solution
Division method: h(k) = k mod 5. Every key ends in 2, so all five keys hash to bucket 2 — a deliberately bad key set that shows why m should be chosen with care.
| Key | Home h(k) | Chain | Stored at |
|---|---|---|---|
| 12 | 2 | append | 2 |
| 42 | 2 | append | 2 |
| 22 | 2 | append | 2 |
| 52 | 2 | append | 2 |
| 32 | 2 | append | 2 |
Final table — 0: — | 1: — | 2: 12 → 42 → 22 → 52 → 32 | 3: — | 4: —
How to write it in the exam
text
0: —
1: —
2: 12 → 42 → 22 → 52 → 32
3: —
4: —Load factor α = 5/5 = 1, but the longest chain has 5 nodes, so a search can take 5 comparisons (worst case O(n)).
How this answer was verified
- tests (chaining engine)
- hashing_chaining.c differential test