Skip to content
Azhimathi Mayam logoDSA Study HubPCCST303 · KTU · S3
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.

Chaining trace (generated)checked by code
KeyHome h(k)ChainStored at
122append2
422append2
222append2
522append2
322append2

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