B-Trees & B+ Trees: Multi-Way Indexing & Block Size Numericals
“B-Tree node constraints, split and merge invariants, B+ tree leaf chaining, and disk block order/fanout derivations.”
1.Multi-Way Balanced Trees: B-Tree Axioms
§ 3.1.A B-Tree of order m is a balanced multi-way search tree designed for disk storage systems where seek latency dominates CPU operations:
1. Every node has at most m children and at most m - 1 keys.
2. Every internal node (except root) has at least lceil m/2 rceil children and at least lceil m/2 rceil - 1 keys.
3. The root has at least 2 children (unless it is a leaf).
4. All leaves appear at the exact same depth (perfect height balance).
B+ Tree Architectural Superiority:
- In a B-Tree, internal nodes hold data pointers, reducing fanout.
- In a B+ Tree, internal nodes store keys and block pointers only. This maximizes fanout, resulting in extremely shallow trees (height 3 to 4 for hundreds of millions of records).
- All leaves are linked sequentially, allowing range queries (WHERE age BETWEEN 20 AND 30) to execute via linear scan without tree re-traversals.
2.Disk Block Size & Order Derivation Math
§ 3.2.In database systems, each tree node is sized to fit exactly within a single physical disk block of size B bytes.
Let:
- B: Disk block size (bytes)
- K: Search key size (bytes)
- P: Disk block pointer size (bytes)
- P_r: Record pointer size (bytes)
1. Internal Node Order p:
An internal node of order p stores p block pointers and p - 1 keys:
p P + (p - 1) K <= B
p * (P + K) - K <= B implies p <= lfloor frac{B + K}{P + K} rfloor.
2. Leaf Node Capacity q:
A leaf node stores q pairs of (Key + Record Pointer) plus 1 block pointer to the next leaf sibling:
q * (K + P_r) + P <= B implies q <= lfloor frac{B - P}{K + P_r} rfloor.
3. Worked Problem: B+ Tree Order & Maximum Key Derivation
Do not forget the single sibling pointer P in the leaf node equation.
Problem: A database file system has a disk block size of B = 512 bytes. In a B+ tree index, search keys are K = 8 bytes, block pointers are P = 4 bytes, and record pointers are Pr = 6 bytes. Calculate the maximum order p of an internal node and the maximum capacity q of a leaf node.
Step 1: Formulate internal node equation:
p P + (p - 1) K <= B
4p + 8(p - 1) <= 512
4p + 8p - 8 <= 512
12p <= 520
p = floor(520 / 12) = 43.
Maximum order of internal node p = 43 (stores 43 block pointers and 42 keys).
Step 2: Formulate leaf node equation:
q * (K + Pr) + P <= B
q * (8 + 6) + 4 <= 512
14q + 4 <= 512
14q <= 508
q = floor(508 / 14) = 36.
Maximum leaf node capacity q = 36 record entries.
Final Answer: Internal order p = 43, Leaf capacity q = 36 records.
Primary Academic References & Exam Sources
Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.
Curated for clarity, rigorous numerical solving, and semester excellence:
Visual thinkers who want to see each algorithm step animated clearly.
GATE-targeted coverage with step-by-step GATE PYQ walkthroughs.