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 and , 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 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)
| Symbol | Meaning |
|---|---|
| Number of primary buckets currently in use (the address space is ). | |
| Number of buckets initially (round 0). It is fixed and never changes; the round- address space is buckets before any split of that round. | |
| Round level (also called level / round number). Starts at . | |
| Hash function of the current round: . | |
| Hash function of the next round: . | |
| Split pointer: the next bucket to be split. . | |
| Number of records currently stored (used in the load factor). | |
| Load factor where = capacity (records per bucket). Some texts use (records per bucket) — see §3. | |
| Bucket capacity (max records per bucket). |
Key relation: at any moment the number of buckets is Because we start a round with buckets and have split of them so far.
Range of the split pointer: . When reaches , the round is complete: set and . itself is not changed (it is the initial bucket count), so the address space at the start of the next round is , i.e. it has doubled.
Convention note (important for GATE). Two conventions appear:
- Elmasri–Navathe style: level starts at , = initial bucket count, . This is what we use above and what most GATE questions assume.
- Other texts (e.g. Ramakrishnan–Gehrke) write with the initial bucket count, or take the initial count to be a power of 2 and write . The mechanics (split pointer, one split per insertion, round-robin) are identical; only the labelling of differs.
Which to use: if the question gives "initial buckets" and asks for , use (Elmasri–Navathe). If it says "" explicitly, follow the question's own formula. Always state the formula you used.
The two hash functions and the search rule
At round with split pointer :
- Buckets have already been split this round → they are addressed by .
- Buckets have not been split yet → they are addressed by .
Search rule for key :
- Compute .
- If , recompute (that bucket has already split).
- Look in bucket (and its overflow chain, if any).
Equivalently: compute ; if the result is use it, else use . Both give the same bucket — verify with the worked example below.
Why it works: is either equal to or equal to . So a key that hashes to an already-split bucket under either stays at or moves to (the newly created bucket). The search rule catches exactly this.