G27
Self-checkedTier 1 11 min readdbms.b-plus-tree

B+ trees

B+ trees, the index structure of database systems: all keys and record pointers in the leaves, inner nodes only as signposts, leaves chained for range queries; node layouts and how the orders follow from the block size, search (always as many block reads as levels), insertion (a leaf split copies the key up, an inner split moves it up), deletion (borrow or merge, separators may remain), range queries, the minimum and maximum number of keys for a height, heights for n keys, and the comparison with B trees; every animation is a snapshot of a real tree and the extreme trees were built node by node.

Why it exists

The B tree of the previous page is balanced and flat, but a database needs two more things: range queries (all records with keys between aa and bb) and the highest possible fan-out of the inner nodes. The B+ tree keeps all keys and record pointers in the leaves, uses the inner nodes only as signposts (so more of them fit in a block) and links the leaves into a sorted chain. It is the standard index of nearly every database system, and GATE asks for its orders, its capacity and the result of insertions and deletions.

Prerequisites

You need the B tree: order, splitting and merging (B trees).

Precise definitions

A B+ tree with internal order mm and leaf capacity LL:

  • Inner nodes hold up to m−1m - 1 keys k1<⋯<kjk_1 < \cdots < k_{j} and j+1j + 1 children; the subtree of child ii contains the keys ki≤x<ki+1k_{i} \le x < k_{i+1} (with k0=−∞k_0 = -\infty, kj+1=+∞k_{j+1} = +\infty): a key equal to a separator is in the right subtree. Non-root inner nodes have at least ⌈m/2⌉\lceil m/2 \rceil children; the root has at least 22 (unless it is a leaf).
  • Leaves hold up to LL keys, each with a record pointer (or the record), and a pointer to the next leaf. Non-root leaves hold at least ⌈L/2⌉\lceil L/2 \rceil keys.
  • Every key of the file appears in a leaf; the keys in inner nodes are copies (separators) and some of them may no longer exist in the file.
  • All leaves are at the same depth.

Orders from the block size (BB block size, VV key, PP block pointer, PrP_r record pointer):

  • inner node: pp pointers and p−1p - 1 keys: pP+(p−1)V≤Bp P + (p - 1) V \le B, so p=⌊(B+V)/(P+V)⌋p = \lfloor (B + V)/(P + V) \rfloor;
  • leaf: LL pairs (key, record pointer) and one next-leaf pointer: L(V+Pr)+P≤BL (V + P_r) + P \le B, so L=⌊(B−P)/(V+Pr)⌋L = \lfloor (B - P)/(V + P_r) \rfloor.

Example: B=512B = 512, V=9V = 9, P=6P = 6, Pr=7P_r = 7: p=⌊521/15⌋=34p = \lfloor 521/15 \rfloor = 34 and L=⌊506/16⌋=31L = \lfloor 506/16 \rfloor = 31. (Compare the B tree order 2424 for the same sizes: the signposts are smaller, so more of them fit.)

How it works

Search and range queries

An exact search always descends to a leaf: with hh levels it reads exactly hh nodes (blocks), plus one block for the data record if the leaf holds a record pointer. A B tree may find a key higher up; the B+ tree's cost is the same for every key, which makes performance predictable.

A range query [a,b][a, b]: search for aa (reaches the leaf where aa belongs), then follow the leaf chain, collecting keys, until a key >b> b is met.

A range query on a B+ tree: start — range 20..55

Real tree, not typed
2545655152025303545556575

Outlined node = the node the step works on; shaded = created in this step; bold key = the key being searched or moved. Arrows join the leaves in key order.

Step 0

Range query: all keys from 20 to 55. A B+ tree does it in two phases: search down for 20, then follow the chain of leaves until a key larger than 55 appears.

0 / 6
computed by script: the file and index sizes are computed from their formulas, the trees are built by real insertions and deletions. python3 scripts/gen-db4-traces.py

The tree of the animation has internal order 44 and leaves of up to 33 keys. The query 20..5520..55 reads 22 nodes (the root and the first leaf [5,15,20][5, 15, 20]), then follows the chain to the leaves [25,30,35][25, 30, 35], [45,55][45, 55] and [65,75][65, 75] (33 more reads) and stops there because 65>5565 > 55: the answer is 20,25,30,35,45,5520, 25, 30, 35, 45, 55. No inner node is read twice. In a B tree the keys of a range are scattered over inner nodes and leaves, so the query would climb up and down repeatedly.

Insertion

  1. Search down to the leaf where the key belongs; insert it in sorted order.
  2. If the leaf has more than LL keys, split it: the left leaf keeps the first ⌈(L+1)/2⌉\lceil (L+1)/2 \rceil keys, the right leaf the rest; the smallest key of the right leaf is copied up into the parent as a separator (it stays in the leaf), and the leaf chain is updated.
  3. If the parent now has mm keys it overflows: split it around its median key, which is moved up (not kept below). Repeat toward the root; a root split adds a level.

Insertions into a B+ tree (internal order 4, leaves of at most 3 keys): start — start

Real tree, not typed
(empty)

Outlined node = the node the step works on; shaded = created in this step; bold key = the key being searched or moved. Arrows join the leaves in key order.

Step 0

An empty B+ tree: internal nodes hold up to 3 keys (4 children), leaves up to 3 keys. All keys live in the leaves, which are linked from left to right (arrows).

0 / 23
computed by script: the file and index sizes are computed from their formulas, the trees are built by real insertions and deletions. python3 scripts/gen-db4-traces.py

Inserting 5,15,25,35,45,55,65,75,20,305, 15, 25, 35, 45, 55, 65, 75, 20, 30 with m=4m = 4, L=3L = 3: the leaf [5,15,25][5, 15, 25] overflows at 3535; the split gives [5,15][5, 15] and [25,35][25, 35] and 2525 is copied up to a new root. Later splits copy 4545 and 6565 up. The final root is [25,45,65][25, 45, 65] over the leaves [5,15,20][5, 15, 20], [25,30,35][25, 30, 35], [45,55][45, 55], [65,75][65, 75]. Note that the copied key 2525 is both in the root and in a leaf.

Deletion

  1. Search down to the leaf and remove the key. A copy in an inner node may stay: it is still a valid separator.
  2. If the leaf has fewer than ⌈L/2⌉\lceil L/2 \rceil keys, borrow one key from a neighbouring sibling that has more than the minimum (and update the separator in the parent), or merge with a sibling (and remove the separator from the parent).
  3. If an inner node underflows (fewer than ⌈m/2⌉\lceil m/2 \rceil children), borrow through the parent (rotate a separator) or merge with a sibling together with the separator that comes down. A root left with one child is removed.

Deletions from a B+ tree: start — start

Real tree, not typed
2545655152025303545556575

Outlined node = the node the step works on; shaded = created in this step; bold key = the key being searched or moved. Arrows join the leaves in key order.

Step 0

A B+ tree built from the keys 5, 15, 25, 35, 45, 55, 65, 75, 20, 30. Leaves must keep at least 2 keys, internal nodes at least 2 children. Separators in inner nodes may stay as copies of keys that no longer exist.

0 / 11
computed by script: the file and index sizes are computed from their formulas, the trees are built by real insertions and deletions. python3 scripts/gen-db4-traces.py

From the tree above, deleting 1515 is harmless. Deleting 55 leaves the first leaf with one key (minimum 22): it borrows 2525 from its right sibling. Deleting 3535 leaves a leaf that cannot borrow, so two leaves merge and the parent loses a separator. Deleting 4545 ends with a borrow from the left sibling.

Capacity and height

With c=⌈m/2⌉c = \lceil m/2 \rceil and hh levels (the last one the leaves):

  • maximum number of keys: every node full: L⋅mh−1L \cdot m^{h-1};
  • minimum number of keys (h≥2h \ge 2): root with 22 children, other inner nodes with cc children, every leaf with ⌈L/2⌉\lceil L/2 \rceil keys: 2 ch−2⌈L/2⌉2\,c^{h-2} \lceil L/2 \rceil.

How many keys a B+ tree holds: start

Computed by a script, not typed
shape1 level2 levels3 levels4 levels
internal order m = 3, leaf holds 2 keys
internal order m = 4, leaf holds 3 keys
internal order m = 5, leaf holds 4 keys
internal order m = 6, leaf holds 5 keys

Step 0

All keys are in the leaves. Maximum: every node full; minimum: root with 2 children, every other internal node with ⌈m/2⌉ children, every leaf with ⌈L/2⌉ keys.

0 / 4
computed by script: the file and index sizes are computed from their formulas, the trees are built by real insertions and deletions. python3 scripts/gen-db4-traces.py

For p=34p = 34, L=31L = 31: a 33-level tree holds between 2⋅17⋅16=5442 \cdot 17 \cdot 16 = 544 and 31⋅342=35 83631 \cdot 34^2 = 35\,836 keys. A tree with nn keys has ⌈log⁡m(n/L)⌉+1≤h≤⌊log⁡c(n/(2⌈L/2⌉))⌋+2\lceil \log_m (n / L) \rceil + 1 \le h \le \lfloor \log_c (n / (2 \lceil L/2 \rceil)) \rfloor + 2 levels approximately; the exact levels for the block of the earlier pages (B=1024B = 1024, V=9V = 9, P=6P = 6, Pr=7P_r = 7):

Levels needed for n keys (block 1024 bytes, key 9, pointers 6, record pointer 7): start

Computed by a script, not typed
keysB tree, order 47B+ tree, internal order 68, leaf 63
n = 1 000
n = 100 000
n = 1 000 000
n = 100 000 000

Step 0

A B-tree node holds p tree pointers and p − 1 (key, record pointer) pairs, so p = ⌊(B + V + Pr)/(P + V + Pr)⌋ = 47. A B+ internal node holds only keys and tree pointers: p = ⌊(B + V)/(P + V)⌋ = 68; a leaf holds ⌊(B − P)/(V + Pr)⌋ = 63 (key, record pointer) pairs and a next-leaf pointer. The higher fan-out of the B+ tree gives fewer levels. The ranges are the best case (all nodes full) and the worst case (all nodes half full).

0 / 4
computed by script: the file and index sizes are computed from their formulas, the trees are built by real insertions and deletions. python3 scripts/gen-db4-traces.py

A B+ tree with 6868 pointers per inner node and 6363 keys per leaf indexes a million keys in 44 levels; a search reads 44 blocks (and one more for the record). The B tree with the same block size has order 4747 and needs 44 to 55 levels.

B tree against B+ tree

B treeB+ tree
keys and record pointersin every nodeonly in the leaves
inner node holdskeys, record pointers, child pointerskeys and child pointers only
fan-out for the same blocksmaller (order 2424 in the example)larger (inner order 3434)
a key appearsoncein a leaf, and possibly as a copy above
search costbetween 11 and hh blocksexactly hh blocks
range queryclimbs up and downfollows the leaf chain
deletionmay replace by predecessor/successorremoves from a leaf only

Worked examples

EX 1Orders from the block size

Easy

B=1024B = 1024, V=9V = 9, P=6P = 6, Pr=7P_r = 7. Inner order ⌊1033/15⌋=68\lfloor 1033/15 \rfloor = 68 (67 keys per inner node). Leaf capacity ⌊1018/16⌋=63\lfloor 1018/16 \rfloor = 63 keys. B-tree order ⌊1040/22⌋=47\lfloor 1040/22 \rfloor = 47.

EX 2Maximum keys

Easy

Inner order 3434, leaf capacity 3131, 33 levels: root with 3434 children, each of the 3434 children with 3434 leaves, i.e. 342=115634^2 = 1156 leaves of 3131 keys: 35 83635\,836 keys. With 44 levels: 31⋅343=1 218 42431 \cdot 34^3 = 1\,218\,424.

EX 3Minimum keys

Medium

Same tree, 33 levels, leanest: the root has 22 children, each has ⌈34/2⌉=17\lceil 34/2 \rceil = 17 children, so 3434 leaves; each leaf holds at least ⌈31/2⌉=16\lceil 31/2 \rceil = 16 keys: 34⋅16=54434 \cdot 16 = 544 keys. A tree with 544544 to 35 83635\,836 keys can therefore have 33 levels (and fewer or more keys need fewer or more levels).

EX 4A leaf split

Medium

m=4m = 4, L=3L = 3. The leaf [45,55,65][45, 55, 65] receives 7575: [45,55,65,75][45, 55, 65, 75] has 4>34 > 3 keys. The left leaf keeps ⌈4/2⌉=2\lceil 4/2 \rceil = 2 keys [45,55][45, 55], the right leaf gets [65,75][65, 75] and 6565 is copied into the parent: the parent gains the separator 6565 and a child pointer.

EX 5Typical questions

GATE level

(a) "The order of a B+ tree for B=512B = 512, key 99, pointer 66:" ⌊(512+9)/(6+9)⌋=34\lfloor (512 + 9)/(6 + 9) \rfloor = 34. (b) "Maximum number of keys in a B+ tree of order pp (internal) with leaf capacity LL and hh levels:" Lph−1L p^{h-1}. (c) "Why are range queries efficient in a B+ tree?" The leaves are linked in key order. (d) "Do all searches in a B+ tree cost the same?" Yes, hh node reads. (e) "A key in an inner node of a B+ tree:" is a copy that guides the search; the real key (with its record pointer) is in a leaf. (f) "When a B+ leaf splits, which key goes up?" The smallest key of the new right leaf, copied.

Cheat box

Cheat box

  • Inner order p=⌊(B+V)/(P+V)⌋p = \lfloor (B + V)/(P + V) \rfloor; leaf capacity L=⌊(B−P)/(V+Pr)⌋L = \lfloor (B - P)/(V + P_r) \rfloor.
  • All keys in leaves, leaves chained; inner keys are copies; search always reads hh nodes.
  • Leaf split: key COPIED up; inner split: key MOVED up. Root split adds a level.
  • Delete from the leaf; borrow or merge; separators may linger.
  • Keys per hh levels: 2⌈p/2⌉h−2⌈L/2⌉2\lceil p/2 \rceil^{h-2}\lceil L/2 \rceil to Lph−1L p^{h-1}.
  • Larger fan-out than a B tree; range queries along the leaf chain.

Traps and GATE patterns

Connections

Across subjects

No cross-subject links yet.

Within this subject

The B+ tree refines the B tree (B trees) and replaces the static multilevel index (ordered indexes); hashing is the alternative for equality searches (hash-based file organisation).

PYQs

16 previous year questions from your book. I re-solved each one myself (12 by running or simulating, 4 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2025 · Set 2 · NAT · 2 marksQ3 · page 422 of the book
In a B+ tree where each node can hold at most four
key values, a root to leaf path consists of the
following nodes:
A = (49, 77, 83, ), B = (7, 19, 33, 44), C = (20*,
22*, 25*, 26*)
The *-marked keys signify that these are data
entries in a leaf.
Assume that a pointer between keys k1 and k2 points
to a subtree containing keys in [k1, k2), and that when
a leaf is created, the smallest key in it is copied up
into its parent.
A record with key value 23 is inserted into the B+
tree.
The smallest key value in the parent of the leaf that
contains 25* is ______
(Answer in integer)
GATE 2025 · Set 1 · MSQ · 1 markQ4 · page 422 of the book
Consider the following B + tree with 5 nodes, in which a
node can store at most 3 key values. The value 23 is now
inserted in the B + tree. Which of the following options(s)
is/are CORRECT?
  • (a)None of the nodes will split.
  • (b)At least one node will split and redistribute
  • (c)The total number of nodes will remain same
  • (d)The height of the tree will increase.
GATE 2024 · Set 1 · MCQ · 1 markQ6 · page 423 of the book
In a B+Tree , the requirement of atleast half-full(50%)
node occupancy is relaxed for which one of the
following cases?
  • (a)Only the root node
  • (b)All leaf nodes
  • (c)All internal nodes
  • (d)Only the leftmost leaf node
GATE 2020 · NATQ9 · page 423 of the book
Consider a database implemented using B+ tree for file
indexing and installed on a disk drive with block size of 4
KB. The size of search key is 12 bytes and the size of
tree/disk pointer is 8 bytes. Assume that the database has
one million records. Also assume that no node of the B+
tree and no records are present initially in main memory.
Consider that each record fits into one disk block. The
minimum number of disk accesses required to retrieve any
record in the database is ______?
GATE 2019 · MCQ · 1 markQ10 · page 423 of the book
Which one of the following statements is NOT
correct  about the B+ tree data structure used for creating
an index of a relational database table?
  • (a)Each leaf node has a pointer to the next leaf node
  • (b)Non-leaf nodes have pointers to data records
  • (c)B+ tree is a height-balanced tree
  • (d)Key values in each node are kept in sorted order
GATE 2017 · Set 2 · NAT · 2 marksQ11 · page 423 of the book
In a B+ tree, if the search-key value is 8 bytes long, the
block size is 512 bytes and the block pointer size is 2 bytes,
then the maximum order of the B+ tree is ______.

DATABASE MANAGEMENT  SYSTEM
GATE 2016 · Set 2 · MCQ · 2 marksQ12 · page 424 of the book
B+ Trees are considered BALANCED because ...
  • (a)The lengths of the paths from the root to all leaf nodes are all equal.
  • (b)The lengths of the paths from the root to all leaf nodes differ from each other by at most 1.
  • (c)The number of children of any two non-leaf sibling nodes differ by at most 1.
  • (d)The number of records in any two leaf nodes differ by at most 1.
GATE 2015 · Set 3 · NAT · 2 marksQ13 · page 424 of the book
Consider a B+ tree in which the search key is 12 bytes
long, block size is 1024 bytes, recorder pointer is 10
bytes long and the block pointer is 8 bytes long. The
maximum number of keys that can be accommodated in
each non-leaf node of the tree is ______.
GATE 2015 · Set 2 · NAT · 1 markQ14 · page 424 of the book
With reference to the B+ tree index of order 1 shown
below, the minimum number of nodes (including the
Root node) that must be fetched in order to satisfy the
following query:"Get all records with a search key
greater than or equal to 7 and less than 15" is
___________
GATE 2010 · MCQ · 1 markQ17 · page 424 of the book
Consider a B+-tree in which the maximum number of
keys in a node is 5. What is the minimum number of keys
in any non-root node?
  • (a)1
  • (b)2
  • (c)3
  • (d)4
GATE 2009 · MCQ · 2 marksQ18 · page 424 of the book
The following key values are inserted into a B+-tree in
which the order of the internal nodes is 3, and that of the
leaf nodes is 2, in the sequence given below. The order of
internal nodes is the maximum number of tree pointers in
each node, and the order of leaf nodes is the maximum
number of data items that can be stored in it. The B+-tree is
initially empty.

10, 3, 6, 8, 4, 2, 1

The maximum number of times leaf nodes would get split
up as a result of these insertions is
  • (a)2
  • (b)3
  • (c)4
  • (d)5
GATE 2007 · MCQ · 2 marksQ22 · page 425 of the book
The order of a leaf node in a B+-tree is the maximum
number of (value, data record pointer) pairs it can hold.
Given that the block size is 1K bytes, data record pointer
is 7 bytes long, the value field is 9 bytes long and a block
pointer is 6 bytes long, what is the order of the leaf
node?
  • (a)63
  • (b)64
  • (c)67
  • (d)68
GATE 2007 · MCQ · 2 marksQ23 · page 425 of the book
Consider the B+tree in the adjoining figure, where each
node has at most two keys and three links.

Keys K'15 and then K25 are inserted into this tree in that
order. Exactly how many of the following nodes
(disregarding the links) will be present in the tree after the
two insertions?
  • (a)1
  • (b)2
  • (c)3
  • (d)4
GATE 2006 · MCQ · 2 marksQ24 · page 425 of the book
Consider the B+tree in the adjoining figure, where each
node has at most two keys and three links.

Now the key K50 is deleted from the B+tree resulting
after the two insertions made earlier. Consider the
following statements about the B+tree resulting after this
deletion.
i. The height of the tree remains the same.
ii. The node

(disregarding the links) is present in the tree.

DATABASE MANAGEMENT  SYSTEM
iii. The root node remains unchanged (disregarding the
links).

Which one of the following options is true?
  • (a)Statements (i) and (ii) are true
  • (b)Statements (ii) and (iii) are true
  • (c)Statements (iii) and (i) are true
  • (d)All the statements are false
GATE 2007 · MCQQ25 · page 426 of the book
In a database file structure, the search key field is 9
bytes long, the block size is 512 bytes, a record pointer
is 7 bytes and a block pointer is 6 bytes. The largest
possible order of a non-leaf node in a B+ tree
implementing this file structure is.
  • (a)23
  • (b)24
  • (c)34
  • (d)44
GATE 2005 · MCQ · 1 markQ26 · page 426 of the book
Which of the following is a key factor for preferring B+-
trees to binary search trees for indexing database
relations?
  • (a)Database relations have a large number of records
  • (b)Database relations are sorted on the primary key
  • (c)B+-trees require less memory than binary search trees
  • (d)Data transfer from disks is in blocks

Self-check

Question 1

Inner order p=100p = 100, leaf capacity L=99L = 99. What is the maximum number of keys in a B+ tree with 33 levels?

Show answer

99⋅1002=990 00099 \cdot 100^2 = 990\,000.

Question 2

Which key is copied into the parent when the leaf [10,20,30,40][10, 20, 30, 40] (capacity 33) is split?

Show answer

The left leaf keeps ⌈4/2⌉=2\lceil 4/2 \rceil = 2 keys [10,20][10, 20], the right leaf [30,40][30, 40]; the key 3030 is copied up.

Question 3

Why does a B+ tree have a larger fan-out than a B tree for the same block size?

Show answer

Its inner nodes contain no record pointers, only keys and child pointers, so more entries fit in a block.

Question 4

How many block reads does a range query returning kk keys from qq leaves need?

Show answer

hh nodes to reach the first leaf plus q−1q - 1 further leaf reads (plus data blocks if the leaves hold record pointers).

Revision card

One-screen revision

  • Leaves hold all keys and are chained; inner nodes hold copies; all searches read hh nodes.
  • p=⌊(B+V)/(P+V)⌋p = \lfloor (B+V)/(P+V) \rfloor, L=⌊(B−P)/(V+Pr)⌋L = \lfloor (B-P)/(V+P_r) \rfloor.
  • Leaf split copies up, inner split moves up; delete borrows or merges.
  • Keys: 2⌈p/2⌉h−2⌈L/2⌉2\lceil p/2 \rceil^{h-2}\lceil L/2 \rceil to Lph−1L p^{h-1}.

References

  • ·Silberschatz, Korth, Sudarshan, Database System Concepts (7th edition), Chapter 14, Sections 14.3 to 14.5 (B+-tree index files, extensions)
  • ·Elmasri, Navathe, Fundamentals of Database Systems (7th edition), Chapter 17, Section 17.3.2 (B+-trees)

Verification

scripts/enum-checks/db_index_check.py: the B+ tree implemented in scripts/db_tree.py was run through 1200 random insert / delete sequences over eight shapes (internal order 3 to 8, leaf capacity 2 to 7) and after every operation the structure was checked (sorted separators, bounds on every subtree, leaves holding between ceil(L/2) and L keys, internal nodes between ceil(m/2) and m children, all leaves on one level, contents equal a reference set); a search read exactly h nodes (one per level); range queries via the leaf chain returned the sorted filter and scanned exactly the leaves between the first leaf of the lower bound and the first leaf holding a key above the upper bound; the completely full tree and the leanest tree were built node by node (internal orders 3 to 6, leaf capacities 2 to 5, up to 4 levels) and have exactly L m^(h-1) and 2 ceil(m/2)^(h-2) ceil(L/2) keys; the order formulas are the largest p and L that fit the block; the animations are snapshots of the implementation and replay to the expected contents (the range query returns 20, 25, 30, 35, 45, 55). CONVENTIONS: keys equal to a separator belong to the RIGHT subtree; on a leaf overflow the left leaf keeps ceil((L + 1)/2) keys; other books use other choices, which change the shape of examples but not the capacity formulas. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and re-derived against the textbook definitions and the sample database. No defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never

My notes (saved in this browser)