1. Gyanastra
  2. Database Systems
  3. Linear Hashing and Hash Versus Index Comparison
  4. The problem linear hashing solves
Free lesson, no account needed 5 min read

Database Systems · Linear Hashing and Hash Versus Index Comparison

The problem linear hashing solves

This chapter assumes you already know what a hash function is and what a bucket is. We build linear hashing from zero: the split pointer, the round level, the two hash functions hih_i and hi+1h_{i+1}, the load-factor trigger, a full worked insertion sequence, and the search rule. Then we compare static / extendible / linear hashing, and hashing versus B+ tree indexes for equality and range queries.


Static hashing fixes the number of buckets MM forever. If the file grows, buckets overflow into chains; if it shrinks, space is wasted. You cannot resize without rehashing every record at once (a long stall).

Extendible hashing grows by doubling the directory (an array of pointers) and splitting one bucket at a time. It needs an indirection directory and a global depth / local depth bookkeeping.

Linear hashing (Litwin, 1980) grows one bucket at a time, in a fixed round-robin order, with no directory. It uses only a split pointer and a round level. That is the whole idea: incremental, predictable, directory-free growth.


Vocabulary and notation (define every symbol)

SymbolMeaning
bbNumber of primary buckets currently in use (the address space is 0,1,…,b−10,1,\dots,b-1).
MMNumber of buckets initially (round 0). It is fixed and never changes; the round-ii address space is M⋅2iM\cdot2^{i} buckets before any split of that round.
iiRound level (also called level / round number). Starts at 00.
hi(K)h_i(K)Hash function of the current round: hi(K)=h(K) mod (M⋅2i)h_i(K) = h(K) \bmod (M \cdot 2^{i}).
hi+1(K)h_{i+1}(K)Hash function of the next round: hi+1(K)=h(K) mod (M⋅2i+1)h_{i+1}(K) = h(K) \bmod (M \cdot 2^{i+1}).
ppSplit pointer: the next bucket to be split. 0≤p<M⋅2i0 \le p < M \cdot 2^{i}.
nnNumber of records currently stored (used in the load factor).
LLLoad factor =n/(b⋅c)= n / (b \cdot c) where cc = capacity (records per bucket). Some texts use n/bn/b (records per bucket) — see §3.
ccBucket capacity (max records per bucket).

Key relation: at any moment the number of buckets is b=M⋅2i+p.b = M\cdot 2^{i} + p . Because we start a round with M⋅2iM\cdot 2^i buckets and have split pp of them so far.

Range of the split pointer: 0≤p≤M⋅2i0 \le p \le M\cdot 2^{i}. When pp reaches M⋅2iM\cdot 2^{i}, the round is complete: set i←i+1i \leftarrow i+1 and p←0p \leftarrow 0. MM itself is not changed (it is the initial bucket count), so the address space at the start of the next round is M⋅2i+1M\cdot2^{i+1}, i.e. it has doubled.

Convention note (important for GATE). Two conventions appear:

  • Elmasri–Navathe style: level ii starts at 00, MM = initial bucket count, hi=h mod (M⋅2i)h_i = h \bmod (M\cdot 2^i). This is what we use above and what most GATE questions assume.
  • Other texts (e.g. Ramakrishnan–Gehrke) write hLevel(K)=h(K) mod (2Level⋅N)h_{\text{Level}}(K) = h(K) \bmod (2^{\text{Level}}\cdot N) with NN the initial bucket count, or take the initial count to be a power of 2 and write hi=h mod 2ih_i = h \bmod 2^i. The mechanics (split pointer, one split per insertion, round-robin) are identical; only the labelling of ii differs.

Which to use: if the question gives "initial MM buckets" and asks for hih_i, use hi=h mod (M⋅2i)h_i = h \bmod (M\cdot 2^i) (Elmasri–Navathe). If it says "hi(K)=K mod 2ih_i(K)=K \bmod 2^i" explicitly, follow the question's own formula. Always state the formula you used.


The two hash functions and the search rule

At round ii with split pointer pp:

  • Buckets 0,1,…,p−10,1,\dots,p-1 have already been split this round → they are addressed by hi+1h_{i+1}.
  • Buckets p,p+1,…,M⋅2i−1p,p+1,\dots,M\cdot2^{i}-1 have not been split yet → they are addressed by hih_i.

Search rule for key KK:

  1. Compute x=hi(K)x = h_i(K).
  2. If x<px < p, recompute x=hi+1(K)x = h_{i+1}(K) (that bucket has already split).
  3. Look in bucket xx (and its overflow chain, if any).

Equivalently: compute hi+1(K)h_{i+1}(K); if the result is <b< b use it, else use hi(K)h_i(K). Both give the same bucket — verify with the worked example below.

Why it works: hi+1(K)h_{i+1}(K) is either equal to hi(K)h_i(K) or equal to hi(K)+M⋅2ih_i(K) + M\cdot 2^{i}. So a key that hashes to an already-split bucket x<px<p under hih_i either stays at xx or moves to x+M⋅2ix + M\cdot2^i (the newly created bucket). The search rule catches exactly this.


Pages 1–2 of 2