1. Gyanastra
  2. Data Structures
  3. UGC NET: Advanced Data Structures
  4. B-Trees, B+ Trees and B Star Trees
Free lesson, no account needed 11 min read 12 practice questions after it
Asked in past papers3 times
  • UGC NET202320132009

Data Structures · UGC NET: Advanced Data Structures

B-Trees, B+ Trees and B Star Trees

Overview

B-tree, B+ tree and B tree* are balanced multiway search trees designed mainly for disk-based storage, where one node is usually one disk block.
A B-tree keeps all leaves at the same level and stores keys plus data pointers in any node. A B+ tree stores all actual records/data pointers only in linked leaf nodes and uses internal nodes as an index.
A B* tree is a B-tree variant that delays splitting by redistributing keys with siblings, giving at least two-thirds occupancy for non-root nodes.
You need basic binary search tree search, insertion and deletion ideas, plus disk block and pointer accounting. These structures are standard in DBMS file organisation, indexing and file systems.

Key concepts

  • Order mm used here means the maximum number of children a node may have. A node with kk keys has exactly k+1k+1 children. Therefore maximum keys per node is m−1m-1.
  • For a B-tree of order mm, every non-root node must have at least ⌈m/2⌉\lceil m/2\rceil children, hence at least ⌈m/2⌉−1\lceil m/2\rceil-1 keys. The root may have fewer.
  • In CLRS minimum degree tt notation, a node has at most 2t−12t-1 keys and at most 2t2t children. Every non-root node has at least t−1t-1 keys and at least tt children. Relation with the order convention: maximum children m=2tm=2t.
  • All leaves of a B-tree are at the same depth. Insertion grows the tree upward by splitting the root; it never pushes leaves downward.
  • A B+ tree keeps actual data pointers/records only at the leaf level. Internal nodes contain only search-key copies and child pointers. Leaves are linked left-to-right for fast range queries.
  • A B tree* is a B-tree with higher minimum occupancy: non-root nodes are at least two-thirds full. On overflow, keys are first redistributed to a sibling; if both relevant nodes are full, two nodes split into three.
  • A split promotes a median key to the parent. In CLRS, a full node has 2t−12t-1 keys; the median key y.key[t]y.key[t] moves up, left and right parts get t−1t-1 keys each.
  • Deletion first removes from a leaf if possible. If a node underflows, borrow from a sibling; otherwise merge with a sibling and a separator key from the parent. The underflow may propagate upward.
  • A node stores keys and child pointers. A non-leaf B-tree node with mm children has m−1m-1 keys and mm pointers. A B+ tree internal node with nn keys has n+1n+1 pointers.

How it works

  1. Search in a B-tree. Start at the root. Compare the target key with the sorted keys in the node. If found, report success. If not, follow the child pointer between the two keys where the target lies.
    Repeat until a leaf is reached.
  2. Insertion in a B-tree. If the root is full, split it first and create a new root. Then descend towards the correct leaf. Before entering a full child, split that child and insert its median key into the parent.
    Finally insert the new key into the non-full leaf.
  3. Split operation. Let a full node contain 2t−12t-1 keys in CLRS notation. The median key moves to the parent. The left part keeps t−1t-1 keys, the right part keeps t−1t-1 keys, and the child pointers are divided accordingly.
    In an order-mm tree, when a full node receives one extra key, the middle of the combined keys moves upward.
  4. Why B-tree height increases only at the root. A split inside the tree only moves a key to the parent. If the root splits, a new root is created above it, so all leaves remain at the same depth.
    This preserves the balanced-height property.
  5. Deletion cases. If the key is in a leaf and removal still leaves enough keys, delete it. If removal causes underflow, borrow a key from a left or right sibling.
    If borrowing is impossible, merge the node with a sibling and the separator key from the parent. If the key is in an internal node, replace it with its predecessor or successor from a leaf, then delete that leaf key.
    If both children adjacent to an internal key have the minimum number of keys, merge them with the key, remove the key from the parent, and propagate underflow if needed.
  6. B+ tree operations. Search always goes down to a leaf. Insertion inserts into the correct leaf; if the leaf splits, the first key of the new right leaf is copied up to the parent. Internal splits promote a median key.
    For a range query, find the first qualifying key in a leaf, then follow leaf next-pointers sequentially.
  7. B tree insertion.* When a node overflows, try to redistribute some keys to a sibling. Update the separator key in the parent.
    If both relevant nodes are full, split two full nodes into three nodes, each about two-thirds full, and move the required separator keys upward. This reduces the number of splits and increases storage utilisation.
Figure. The insert starts by finding the correct leaf; if the leaf is full, it splits at the median and moves that key to the parent. Full parents split recursively, and a new root is created when the root splits.

Formulas

  • Use order mm = maximum number of children; maximum keys = m−1m-1.

  • Minimum children of a non-root internal node:
    ⌈m2⌉\left\lceil \frac{m}{2} \right\rceil

  • Minimum keys of a non-root node:
    ⌈m2⌉−1\left\lceil \frac{m}{2} \right\rceil -1

  • CLRS minimum degree tt: maximum keys =2t−1=2t-1, minimum non-root keys =t−1=t-1, maximum children =2t=2t, minimum non-root children =t=t.

  • B* tree non-root occupancy: at least two-thirds full. Under the maximum-children convention, minimum children is often written as
    ⌈2m3⌉\left\lceil \frac{2m}{3} \right\rceil and minimum keys as
    ⌈2m3⌉−1.\left\lceil \frac{2m}{3} \right\rceil -1. Some books state “two-thirds of capacity”; follow the convention stated in the question.

  • Maximum height with root height 00. Let t=⌈m/2⌉t=\lceil m/2\rceil. Minimum number of keys in a B-tree of height hh is
    2th−1.2t^{h}-1. Hence h≤log⁡t ⁣(n+12).h \le \log_t\!\left(\frac{n+1}{2}\right).

  • Non-leaf B-tree node memory: with key size KK, pointer size PP, and maximum children MM,
    K(M−1)+PM=(K+P)M−K.K(M-1)+PM=(K+P)M-K.

  • B+ tree internal node with nn keys and n+1n+1 child pointers, block size BB:
    nK+(n+1)P≤B⇒nmax⁡=⌊B−PK+P⌋.nK+(n+1)P \le B \quad\Rightarrow\quad n_{\max}=\left\lfloor\frac{B-P}{K+P}\right\rfloor.

  • B+ tree leaf node with nn keys, record pointer size RR, and one next-leaf pointer PsP_s:
    n(K+R)+Ps≤B⇒nmax⁡=⌊B−PsK+R⌋.n(K+R)+P_s \le B \quad\Rightarrow\quad n_{\max}=\left\lfloor\frac{B-P_s}{K+R}\right\rfloor. If the next-leaf pointer is not counted, use ⌊B/(K+R)⌋\lfloor B/(K+R)\rfloor.

  • Average split bound. Let pp be the number of nodes, S=p−1S=p-1 total splits while building from empty, and tmin⁡=⌈m/2⌉−1t_{\min}=\lceil m/2\rceil-1. Since each non-root node has at least tmin⁡t_{\min} keys,
    Sn≤1tmin⁡=1⌈m/2⌉−1.\frac{S}{n} \le \frac{1}{t_{\min}} =\frac{1}{\lceil m/2\rceil-1}.

Worked examples

Example 1: B-tree node memory. A B-tree uses maximum children M=100M=100. Each key is 3232 bytes and each child pointer is 44 bytes. A non-leaf node has M−1=99M-1=99 keys and M=100M=100 pointers. Memory =32×99+4×100=3168+400=3568=32\times 99+4\times 100=3168+400=3568 bytes. Using the formula: (32+4)100−32=3600−32=3568(32+4)100-32=3600-32=3568.
If one disk block is 81928192 bytes, solve 36M−32≤819236M-32\le8192. Then 36M≤822436M\le8224, so M≤228.44M\le228.44. Maximum integer M=228M=228, giving 36×228−32=8208−32=817636\times228-32=8208-32=8176 bytes, which fits.

Example 2: B+ tree fanout. A B+ tree uses disk blocks of 10241024 bytes, key size 1212 bytes, child pointer size 88 bytes. For an internal node, maximum keys nn satisfy 12n+8(n+1)≤102412n+8(n+1)\le1024. Thus 20n+8≤102420n+8\le1024, 20n≤101620n\le1016, n≤50.8n\le50.8, so nmax⁡=50n_{\max}=50, with 5151 child pointers.
Check: 50×12+51×8=600+408=1008≤102450\times12+51\times8=600+408=1008\le1024. If each leaf also has one next-leaf pointer of 88 bytes and record pointer 88 bytes, leaf maximum keys satisfy n(12+8)+8≤1024n(12+8)+8\le1024, so 20n≤101620n\le1016, again nmax⁡=50n_{\max}=50.

Example 3: Insertion into an order-3 B-tree. This is a 2-3 tree: maximum 22 keys per node. Insert 1010: root [10][10]. Insert 2020: root [10,20][10,20]. Insert 3030: node overflows as [10,20,30][10,20,30]; median 2020 moves up. Root [20][20], children [10][10] and [30][30].
Insert 4040: goes to right child [30,40][30,40]. Insert 5050: right child overflows as [30,40,50][30,40,50]; median 4040 moves up. Root becomes [20,40][20,40], children [10][10], [30][30], [50][50]. Insert 6060: goes to rightmost child [50][50] and becomes [50,60][50,60].
Final root [20,40][20,40], children [10][10], [30][30], [50,60][50,60].

Example 4: Maximum height. For order m=5m=5, t=⌈5/2⌉=3t=\lceil5/2\rceil=3. Minimum keys for height hh is 2⋅3h−12\cdot3^h-1. For h=3h=3, minimum keys =2⋅27−1=53=2\cdot27-1=53. For h=4h=4, minimum keys =2⋅81−1=161=2\cdot81-1=161. If n=100n=100, height 33 is possible because 53≤10053\le100, but height 44 is impossible because 161>100161>100.
Hence maximum height is 33 under root height 00.

Example 5: Statement type. Statement I: In a B+ tree, sequential range queries are efficient because all leaves are linked. True. Statement II: A B* tree tries redistribution with a sibling before splitting a full node. True.
Statement III: In a standard B-tree, data pointers occur only at leaf nodes. False; a B-tree may store data pointers with keys in internal nodes also. Therefore I and II are true, III is false.

Comparison

FeatureB-treeB+ treeB* tree
Data pointersIn all nodesOnly in leavesIn all nodes, like B-tree
Internal node keysActual keysRouting key copiesActual keys
Leaves linkedUsually noYes, left-to-rightUsually no
Search endsMay end at internal nodeAlways at a leafMay end at internal node
Range queryInorder/backtrackingEfficient by leaf linksInorder/backtracking
Minimum occupancyAbout half fullAbout half fullAt least two-thirds full
Overflow handlingSplit full nodeSplit leaf/internal nodeRedistribute to sibling first; then split
Main advantageGeneral balanced indexFast range and sequential accessHigh storage utilisation, fewer splits
ConventionMaximum keysMinimum non-root keysMaximum children
Order mmm−1m-1⌈m/2⌉−1\lceil m/2\rceil-1mm
CLRS degree tt2t−12t-1t−1t-12t2t

Revision summary

  • Order mm here means maximum children, not maximum keys.
  • Maximum keys in order mm is m−1m-1; a node with kk keys has k+1k+1 children.
  • CLRS tt: maximum keys 2t−12t-1, minimum non-root keys t−1t-1.
  • Split promotes the median key; in CLRS the median is the tt-th key.
  • B-tree grows upward by splitting the root, keeping all leaves at one level.
  • Deletion underflow: borrow first; if impossible, merge with separator.
  • B+ tree: data only at leaves; leaves linked; internal keys are copies.
  • B* tree: non-root nodes at least two-thirds full; redistribute before split.
  • Non-leaf B-tree memory: K(M−1)+PMK(M-1)+PM, not just keys.
  • B+ internal node with nn keys has n+1n+1 child pointers.
  • Height bound uses t=⌈m/2⌉t=\lceil m/2\rceil: 2th−12t^h-1 minimum keys.
  • Average split bound is ≤1/(⌈m/2⌉−1)\le 1/(\lceil m/2\rceil-1).

Previous-year exam insights

  • Direct formula questions ask maximum/minimum keys, minimum children, node memory, or fanout from block size.
    Check whether the question uses order mm or CLRS minimum degree tt.
  • Numeric questions often require two steps: first find fanout from block size, then use that fanout in height or memory calculation.
  • Insertion questions test the exact median that moves upward.
    In a 2-3 tree, it is the middle of three keys; in CLRS, it is the tt-th key of the full node.
  • Deletion questions trap students on borrow versus merge.
    If both adjacent children have minimum keys, merge with the separator; do not try to borrow.
  • Statement and match-list questions mix B-tree, B+ tree and B* tree properties.
    B+ leaves are linked and data is only at leaves; B* has two-thirds occupancy and redistribution.
  • A common wrong option counts mm keys for order mm, or forgets the extra child pointer in a node with kk keys.
  • The average-split formula follows from counting minimum keys per non-root node and the fact that each split adds one node.
  • For B+ tree block-size questions, count internal child pointers as n+1n+1, and count leaf record pointers plus any next-leaf pointer if the question mentions it.

Practice at PARIKSHA

You are ready for the PARIKSHA tests of this sub-topic when you can:

  • State maximum keys, minimum keys and minimum children for a B-tree of order mm and for CLRS minimum degree tt.
  • Convert between order mm and degree tt and avoid mixing their formulas.
  • Compute the memory of a non-leaf B-tree node from key size, pointer size and maximum children.
  • Compute maximum keys in a B+ tree internal node and leaf node from block size and pointer sizes.
  • Trace insertion into a small B-tree and identify the median key moved upward at each split.
  • Apply deletion rules for leaf underflow, internal-node deletion and merging with a separator.
  • Derive and use the maximum height bound with root height 00.
  • Explain why B-trees grow upward and why this preserves equal leaf depth.
  • Distinguish B-tree, B+ tree and B* tree on data placement, leaf links, occupancy and split strategy.
  • Answer statement-type and match-list questions on B+ leaf links, B* two-thirds occupancy and B-tree data pointers.

Attempt the sub-topic test first, then the subject test.

Pages 1–2 of 2