1. Gyanastra
  2. Database Systems
  3. Extendible Hashing Worked Insertions
  4. Worked sequence A — bucket capacity b = 2
Free lesson, no account needed 4 min read

Database Systems · Extendible Hashing Worked Insertions

Worked sequence A — bucket capacity b = 2

Hash values are 4-bit strings. Insert in this order: h=0101, 1100, 0110, 1010, 1110, 0100, 1011h = 0101,\ 1100,\ 0110,\ 1010,\ 1110,\ 0100,\ 1011.

Step 0 — initial state

g=0g = 0, directory has 20=12^{0}=1 entry, one empty bucket with l=0l=0.

g = 0
dir: [0]  B0 (l=0): {}

Step 1 — insert 0101

g=0g=0 ⇒ index 0. B0B_0 has room (0 < 2). Insert.

g = 0
dir: [0]  B0 (l=0): {0101}

Step 2 — insert 1100

Index 0 again. B0B_0 now has 2 keys = capacity. Insert succeeds (2 ≤ 2).

g = 0
dir: [0]  B0 (l=0): {0101, 1100}

Step 3 — insert 0110

Index 0. B0B_0 is full (2 keys). lB=0=gl_B = 0 = g ⇒ double directory to g=1g=1 (2 entries), then split.

  • Directory after doubling: [0]→B0, [1]→B0 (both point to the same bucket).
  • Split on bit 1 (since lB+1=1l_B+1 = 1):
    • 0101 → bit1 = 0 → B0B_0
    • 1100 → bit1 = 1 → B1B_1
    • 0110 → bit1 = 0 → B0B_0
  • New local depths: l=1l=1 for both.
g = 1
dir: [0]  B0 (l=1): {0101, 0110}
     [1]  B1 (l=1): {1100}

Step 4 — insert 1010

First g=1g=1 bit of 1010 is 1 → index 1 → B1B_1. B1B_1 has 1 key, room for one more. Insert.

g = 1
dir: [0]  B0 (l=1): {0101, 0110}
     [1]  B1 (l=1): {1100, 1010}

Step 5 — insert 1110

First bit = 1 → B1B_1, which is full. lB1=1=gl_{B_1} = 1 = g ⇒ double directory to g=2g=2 (4 entries), then split B1B_1.

  • Directory after doubling: [00]→B0, [01]→B0, [10]→B1, [11]→B1.
  • Split B1B_1 on bit 2:
    • 1100 → bit2 = 1 → B11B_{11}
    • 1010 → bit2 = 0 → B10B_{10}
    • 1110 → bit2 = 1 → B11B_{11}
  • New local depths: l=2l=2 for both. B0B_0 keeps l=1l=1.
g = 2
dir: [00]  B0  (l=1): {0101, 0110}
     [01]  B0  (l=1): {0101, 0110}
     [10]  B10 (l=2): {1010}
     [11]  B11 (l=2): {1100, 1110}

Step 6 — insert 0100

First g=2g=2 bits of 0100 are 01 → index 01 → B0B_0, which is full ({0101, 0110}). lB0=1<g=2l_{B_0}=1 < g=2 ⇒ split B0B_0 only, no doubling.

  • Split on bit 2 (the 2nd bit from the left, not the directory prefix): 0101 → bit2 = 1, 0110 → bit2 = 1, 0100 → bit2 = 1. All three keys go to B01B_{01}; B00B_{00} is created empty. Both new buckets get l=2l=2.
g = 2
dir: [00]  B00 (l=2): {}
     [01]  B01 (l=2): {0101, 0110, 0100}   <- 3 keys > capacity 2
     [10]  B10 (l=2): {1010}
     [11]  B11 (l=2): {1100, 1110}
  • B01B_{01} is still over capacity, so repeat from step 4 (cascading split). lB01=2=gl_{B_{01}}=2=g ⇒ double the directory to g=3g=3 (8 entries), then split B01B_{01} on bit 3: 0101 → 0 and 0100 → 0 go to B010B_{010}; 0110 → 1 goes to B011B_{011}. Both get l=3l=3.
g = 3
dir: [000] B00  (l=2): {}
     [001] B00  (l=2): {}
     [010] B010 (l=3): {0101, 0100}
     [011] B011 (l=3): {0110}
     [100] B10  (l=2): {1010}
     [101] B10  (l=2): {1010}
     [110] B11  (l=2): {1100, 1110}
     [111] B11  (l=2): {1100, 1110}

Step 7 — insert 1011

First 3 bits = 101 → B10B_{10}, which has 1 key. Insert.

g = 3
dir: [000] B00  (l=2): {}
     [001] B00  (l=2): {}
     [010] B010 (l=3): {0101, 0100}
     [011] B011 (l=3): {0110}
     [100] B10  (l=2): {1010, 1011}
     [101] B10  (l=2): {1010, 1011}
     [110] B11  (l=2): {1100, 1110}
     [111] B11  (l=2): {1100, 1110}

Final state of sequence A: g=3g=3, 5 buckets (B00B_{00} empty with l=2l=2; B010B_{010}, B011B_{011} with l=3l=3; B10B_{10}, B11B_{11} with l=2l=2). Every bucket has ≤ 2 keys. ✔ Invariant check: entries per bucket 2+1+1+2+2=8=232+1+1+2+2 = 8 = 2^{3}.

Sequence A summary table

Inserthhgg beforeindexbucketfull?actiongg after
0101010100B0noinsert0
1100110000B0no (1→2)insert0
0110011000B0yesdouble + split1
1010101011B1noinsert1
1110111011B1yesdouble + split2
01000100201B0yessplit B0 (all keys go to B01), B01 overflows: double + split3
101110113101B10noinsert3
Pages 1–2 of 2