1. Gyanastra
  2. Database Systems
  3. Linear Hashing: Overflow Variant, Later-Round Splits and Search Cost
  4. The problem linear hashing solves
Free lesson, no account needed 4 min read

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

The problem linear hashing solves

Static hashing fixes the number of buckets MM. As the file grows, buckets overflow into chains and search cost degrades. Extendible hashing fixes this with a directory that doubles, but the directory is an extra indirection and can itself be large.

Linear hashing (Litwin, 1980) grows the file one bucket at a time, with no directory. It keeps a split pointer that sweeps left to right; when it reaches the end of the current bucket range, the range doubles and the pointer resets to 0.

Two variants exist:

VariantWhat triggers a split
Overflow-triggered (simple) linear hashingA split is done whenever some bucket overflows (an insertion lands in a full bucket)
Load-factor-triggered linear hashingA split is done whenever the load factor exceeds a threshold, wherever the overflow happened (keeps the load factor bounded)

Many exam questions use the overflow-triggered variant, because it gives a deterministic insertion-by-insertion trace; always follow the trigger stated in the question. This chapter covers that variant.

Notation and the two hash functions

State the parameters first; every worked example below uses these symbols.

SymbolMeaning
MMNumber of buckets at the start of the current round (a power of 2)
nnNumber of buckets currently in use, M≤n≤2MM \le n \le 2M
ppSplit pointer: index of the next bucket to be split, 0≤p<M0 \le p < M
h0(K)=K mod Mh_0(K) = K \bmod MHash function used before a bucket is split
h1(K)=K mod 2Mh_1(K) = K \bmod 2MHash function used after a bucket is split
bbBucket capacity (records per bucket)

The rule that decides the bucket of a key KK:

bucket(K)={h1(K)=K mod 2M,if h0(K)<p(bucket h0(K) has already been split)h0(K)=K mod M,otherwise\text{bucket}(K)= \begin{cases} h_1(K)=K \bmod 2M, & \text{if } h_0(K) < p \quad(\text{bucket } h_0(K) \text{ has already been split})\\[2pt] h_0(K)=K \bmod M, & \text{otherwise} \end{cases}

Why this works: h1(K)h_1(K) is either h0(K)h_0(K) or h0(K)+Mh_0(K)+M. A key with h0(K)=jh_0(K)=j belongs to bucket jj while that bucket is not yet split (j≥pj\ge p); once bucket jj has been split (j<pj<p), h1h_1 decides between bucket jj and bucket j+Mj+M. The test is on h0(K)h_0(K), not on h1(K)h_1(K): a key that belongs to a new bucket has h1(K)≥M>ph_1(K)\ge M>p and would never pass the test h1(K)<ph_1(K)<p.

Convention note (state this in your answer). Some texts (Elmasri–Navathe style) number buckets 1..M1..M and write h0=K mod Mh_0 = K \bmod M with the convention that remainder 00 means bucket MM. Silberschatz-style and most GATE questions number buckets 0..M−10..M-1 and use plain K mod MK \bmod M. Use 0-based unless the question's diagram is clearly 1-based; if 1-based, replace every "K mod MK \bmod M" by "((K−1) mod M)+1((K-1) \bmod M)+1". The arithmetic is identical, only the labels shift.

Round structure. A round begins with MM buckets, n=Mn = M, p=0p = 0. Each split adds one bucket at the end (index nn), so nn grows by 1 and pp grows by 1. When pp reaches MM, the round ends: set M←2MM \leftarrow 2M, p←0p \leftarrow 0, and n=Mn = M again (the file now has 2M2M buckets, all addressed by the new h0h_0).

The overflow-triggered split procedure (exact steps)

insert(K):
  1. compute target bucket t by the rule in section 2
  2. if bucket t has a free slot: place K there; STOP
  3. else: append K to the overflow chain of bucket t
  4. perform ONE split:
       a. allocate new bucket at index n
       b. redistribute the records of bucket p (the split pointer bucket)
          using h1 = K mod 2M:  records with h1 = p stay in p,
                                records with h1 = p + M move to bucket n
       c. p <- p + 1
       d. if p = M:  M <- 2M ; p <- 0        (round ends)

Two facts that exam questions test:

  • The split is performed on bucket pp, not on the bucket that overflowed. The overflowed bucket keeps its chain until the pointer eventually reaches it.
  • Only one split per insertion, even if the overflowed bucket is still full afterwards.
Pages 1–2 of 2