Database Systems · Extendible Hashing Worked Insertions
The problem it solves
Static hashing fixes the number of buckets at creation. If the file grows, buckets overflow into chains; if it shrinks, space is wasted. Extendible hashing makes the number of buckets dynamic by hashing keys to a binary string and using only a prefix of that string to choose a bucket. The prefix length is the global depth; it grows and shrinks as needed, and the directory doubles (or halves) accordingly.
Definitions and symbols
| Symbol | Name | Meaning |
|---|---|---|
| hash value | A binary string of some fixed length (e.g. 4 bits). We write it explicitly, e.g. . | |
| global depth | Number of leading bits of used by the directory. Directory has entries. | |
| local depth of bucket | Number of leading bits that all keys in bucket share; always. | |
| bucket capacity | Max keys per bucket (given in the problem). | |
| directory | Array of pointers to buckets. |
Bucket-selection rule (the only rule you need): take the first bits of , read them as an integer with ; directory entry points to the bucket holding .
Key invariant: every key in a bucket with local depth has the same first bits. Two directory entries point to the same bucket iff they agree in their first bits (so entries share one bucket).
Convention warning (state this in the exam)
| Convention | Where used | Directory index |
|---|---|---|
| Most-significant-bits-first (leading prefix) | Elmasri–Navathe, Silberschatz, Korth–Sudarshan (the textbook convention; exam questions may use either, so follow the question) | first bits, read left to right |
| Least-significant-bits-first (suffix) | Some older texts / variants | last bits |
Both are self-consistent; mixing them mid-problem gives wrong answers. Follow the bit order the question states (textbooks use leading bits; some papers use the last bits, e.g. ). If nothing is stated, say which one you are using.
Also note the depth naming: Elmasri–Navathe call the global depth and the local depth ; Silberschatz uses for the number of prefix bits and for bucket 's local value. We use and ; the rules are identical.
The split rules (memorise these four lines)
When inserting into a full bucket (local depth ):
- If (bucket is not at global depth): split only. Increment to ; the two new buckets get local depth ; redistribute 's keys plus by their next bit. Directory size unchanged — just repoint the entries that shared : those whose bit at position is 0 point to the new bucket , those with 1 point to .
- If (bucket is at global depth): double the directory first (, directory now entries, each old entry duplicated), then split as in rule 1. Now holds, so the split is a local one.
- No overflow ⇒ no split. Insert into the bucket; nothing else changes.
- Duplicate keys: if the key already exists, do nothing (or update) — never split for a duplicate.
Why rule 2 doubles first: after doubling, the old bucket's entry becomes entries, so the split can hand one entry to each new bucket. Doubling is the only operation that changes .
Deletion / merge (brief):
- Delete the key. If the bucket becomes empty and its buddy (the bucket sharing the same first bits, differing only in bit ) has the same local depth , merge them into one bucket of local depth and repoint both directory entries.
- After merging, if every bucket has , halve the directory (). Repeat while the condition holds.
- Never merge buckets of different local depth, and never let drop below the maximum local depth.
The step-by-step method (use this order every time)
- Compute in binary; write it out fully.
- Read the first bits → directory index .
- Follow to bucket . If has room, insert and stop.
- is full. Compare with :
- → split (rule 1).
- → double directory, then split (rule 2).
- Redistribute: for each key in plus , look at bit number (1-indexed from the left). Bit 0 → bucket ; bit 1 → bucket . Both new buckets get local depth .
- Repoint the directory entries that used to point to .
- If a new bucket is still over capacity (possible when many keys share the next bit), repeat from step 4 on that bucket — this is the "cascading split" case.