1. Gyanastra
  2. Database Systems
  3. Linear Hashing: Overflow Variant, Later-Round Splits and Search Cost
  4. Worked example A: overflow-triggered insertion sequence
Free lesson, no account needed 4 min read

Database Systems · Linear Hashing: Overflow Variant, Later-Round Splits and Search Cost

Worked example A: overflow-triggered insertion sequence

Take M=4M = 4, b=2b = 2 (two records per block), h0=K mod 4h_0 = K \bmod 4, h1=K mod 8h_1 = K \bmod 8. Insert in order:

12, 20, 4, 8, 28, 36, 44, 5212,\ 20,\ 4,\ 8,\ 28,\ 36,\ 44,\ 52

All of these are multiples of 4, so h0=0h_0=0 for every key. Overflow chains hold bb records per overflow block and are written ->.

Initial state: buckets 0–3 empty; n=4n=4, p=0p=0.

Insert 12, 20. Both go to bucket 0 (room): B0: 12,20.

Insert 4. h0(4)=0≥p=0h_0(4)=0\ge p=0 → bucket 0, which is full → 4 goes to its overflow chain; then split bucket p=0p=0 with h1=K mod 8h_1=K\bmod8: 12→412\to4, 20→420\to4, 4→44\to4. All three have h1=4=p+Mh_1=4=p+M, so all move to the new bucket 4. Now p=1p=1, n=5n=5.

B0: --   B1: --   B2: --   B3: --
B4: 12,20 -> 4

Insert 8. h0(8)=0<p=1h_0(8)=0<p=1 → bucket already split → h1(8)=0h_1(8)=0 → bucket 0 (empty): B0: 8.

Insert 28. h0(28)=0<1h_0(28)=0<1 → h1(28)=28 mod 8=4h_1(28)=28\bmod8=4 → bucket 4, which is full → chain; then split bucket p=1p=1 (empty, nothing moves); new bucket 5. p=2p=2, n=6n=6.

B4: 12,20 -> 4,28

Insert 36. h0=0<2h_0=0<2 → h1(36)=4h_1(36)=4 → bucket 4 → new overflow block; split bucket p=2p=2 (empty); new bucket 6. p=3p=3, n=7n=7.

B4: 12,20 -> 4,28 -> 36

Insert 44. h0=0<3h_0=0<3 → h1(44)=4h_1(44)=4 → bucket 4 (second overflow block gets 44); split bucket p=3p=3 (empty); new bucket 7. p=4=Mp=4=M → round ends: M←8M\leftarrow8, p←0p\leftarrow0, n=8n=8.

B4: 12,20 -> 4,28 -> 36,44

Insert 52. Now M=8M=8: h0(52)=52 mod 8=4≥p=0h_0(52)=52\bmod8=4\ge p=0 → bucket 4, full → third overflow block; split bucket p=0p=0 with h1=K mod 16h_1=K\bmod16: bucket 0 holds 88, and 8 mod 16=8=p+M8\bmod16=8=p+M → moves to the new bucket 8. p=1p=1, n=9n=9.

Final state (M=8M=8, p=1p=1, n=9n=9):

B0: --   B1: --   B2: --   B3: --
B4: 12,20 -> 4,28 -> 36,44 -> 52
B5: --   B6: --   B7: --   B8: 8

Lesson from example A. Bucket 4 overflowed repeatedly but was never the bucket at the split pointer, so its chain grew to 3 overflow blocks while the pointer walked over empty buckets. This is the characteristic weakness of the overflow-triggered variant. Search for 52 costs 1+3=41+3=4 bucket accesses.

Pages 1–2 of 2