1. Gyanastra
  2. Database Systems
  3. Extendible Hashing with Last-Bits Keys, Overflow and Deletion
  4. The exact algorithm
Free lesson, no account needed 4 min read

Database Systems · Extendible Hashing with Last-Bits Keys, Overflow and Deletion

The exact algorithm

3.1 Lookup

  1. Compute h(K)=K mod 2ih(K)=K \bmod 2^i.
  2. Use h(K)h(K) as the directory index; follow the pointer to the bucket.
  3. Search the bucket (and its overflow chain, if any) for KK.

3.2 Insert

  1. Look up the bucket for h(K)h(K).
  2. If the bucket has room, insert. Done.
  3. If the bucket is full:
    • Case A — ij<ii_j < i (local depth less than global): split the bucket into two. Increment its local depth to ij+1i_j+1. Redistribute its records by the new bit. Update the 2 i−ij2^{\,i-i_j} directory pointers so half point to the old bucket and half to the new one. Directory size unchanged.
    • Case B — ij=ii_j = i (local depth equals global): first double the directory (i←i+1i \leftarrow i+1, d←2dd \leftarrow 2d; each old entry is copied to two adjacent entries). Then perform the split as in Case A.
    • Repeat rule / Case C: after a split, if the new record's bucket is still full (all records fell on one side), repeat Case A or B. Use an overflow bucket only when more than bb records have the same complete hash value (e.g. duplicates), so no number of extra bits can separate them. Local depth is not increased in that case.

3.3 Delete

  1. Find and remove the record.
  2. If the bucket and its buddy (same local depth iji_j, suffixes differing only in the iji_j-th bit) now hold together at most bb records, merge them into one bucket with local depth ij−1i_j-1 (some texts merge only when a bucket becomes empty; follow the question). A merge can cascade.
  3. After a merge, if every bucket has local depth <i< i, halve the directory (i←i−1i \leftarrow i-1, d←d/2d \leftarrow d/2), keeping one of each pair of identical pointers.

3.4 Disk accesses (the standard GATE counting rule)

  • Directory in main memory: lookup = 1 disk access (read the bucket).
  • Directory on disk: lookup = 1 (read directory) + 1 (read bucket) = 2 disk accesses.
  • Each overflow bucket read adds 1 more access.

Pages 1–2 of 2