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 and ) 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 and leaf capacity :
- Inner nodes hold up to keys and children; the subtree of child contains the keys (with , ): a key equal to a separator is in the right subtree. Non-root inner nodes have at least children; the root has at least (unless it is a leaf).
- Leaves hold up to keys, each with a record pointer (or the record), and a pointer to the next leaf. Non-root leaves hold at least 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 ( block size, key, block pointer, record pointer):
- inner node: pointers and keys: , so ;
- leaf: pairs (key, record pointer) and one next-leaf pointer: , so .
Example: , , , : and . (Compare the B tree order 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 levels it reads exactly 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 : search for (reaches the leaf where belongs), then follow the leaf chain, collecting keys, until a key is met.
A range query on a B+ tree: start — range 20..55
Real tree, not typedOutlined 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.
The tree of the animation has internal order and leaves of up to keys. The query reads nodes (the root and the first leaf ), then follows the chain to the leaves , and ( more reads) and stops there because : the answer is . 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
- Search down to the leaf where the key belongs; insert it in sorted order.
- If the leaf has more than keys, split it: the left leaf keeps the first 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.
- If the parent now has 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 typedOutlined 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).
Inserting with , : the leaf overflows at ; the split gives and and is copied up to a new root. Later splits copy and up. The final root is over the leaves , , , . Note that the copied key is both in the root and in a leaf.
Deletion
- Search down to the leaf and remove the key. A copy in an inner node may stay: it is still a valid separator.
- If the leaf has fewer than 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).
- If an inner node underflows (fewer than 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 typedOutlined 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.
From the tree above, deleting is harmless. Deleting leaves the first leaf with one key (minimum ): it borrows from its right sibling. Deleting leaves a leaf that cannot borrow, so two leaves merge and the parent loses a separator. Deleting ends with a borrow from the left sibling.
Capacity and height
With and levels (the last one the leaves):
- maximum number of keys: every node full: ;
- minimum number of keys (): root with children, other inner nodes with children, every leaf with keys: .
How many keys a B+ tree holds: start
Computed by a script, not typed| shape | 1 level | 2 levels | 3 levels | 4 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.
For , : a -level tree holds between and keys. A tree with keys has levels approximately; the exact levels for the block of the earlier pages (, , , ):
Levels needed for n keys (block 1024 bytes, key 9, pointers 6, record pointer 7): start
Computed by a script, not typed| keys | B tree, order 47 | B+ 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).
A B+ tree with pointers per inner node and keys per leaf indexes a million keys in levels; a search reads blocks (and one more for the record). The B tree with the same block size has order and needs to levels.
B tree against B+ tree
| B tree | B+ tree | |
|---|---|---|
| keys and record pointers | in every node | only in the leaves |
| inner node holds | keys, record pointers, child pointers | keys and child pointers only |
| fan-out for the same block | smaller (order in the example) | larger (inner order ) |
| a key appears | once | in a leaf, and possibly as a copy above |
| search cost | between and blocks | exactly blocks |
| range query | climbs up and down | follows the leaf chain |
| deletion | may replace by predecessor/successor | removes from a leaf only |
Worked examples
EX 1Orders from the block size
Easy, , , . Inner order (67 keys per inner node). Leaf capacity keys. B-tree order .
EX 2Maximum keys
EasyInner order , leaf capacity , levels: root with children, each of the children with leaves, i.e. leaves of keys: keys. With levels: .
EX 3Minimum keys
MediumSame tree, levels, leanest: the root has children, each has children, so leaves; each leaf holds at least keys: keys. A tree with to keys can therefore have levels (and fewer or more keys need fewer or more levels).
EX 4A leaf split
Medium, . The leaf receives : has keys. The left leaf keeps keys , the right leaf gets and is copied into the parent: the parent gains the separator and a child pointer.
EX 5Typical questions
GATE level(a) "The order of a B+ tree for , key , pointer :" . (b) "Maximum number of keys in a B+ tree of order (internal) with leaf capacity and levels:" . (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, 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 ; leaf capacity .
- All keys in leaves, leaves chained; inner keys are copies; search always reads 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 levels: to .
- Larger fan-out than a B tree; range queries along the leaf chain.
Traps and GATE patterns
Connections
Builds on
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
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)
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.
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
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 ______?
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
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
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.
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 ______.
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 ___________
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
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
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
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
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
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
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 , leaf capacity . What is the maximum number of keys in a B+ tree with levels?
Show answerHide
.
Question 2
Which key is copied into the parent when the leaf (capacity ) is split?
Show answerHide
The left leaf keeps keys , the right leaf ; the key 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 answerHide
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 keys from leaves need?
Show answerHide
nodes to reach the first leaf plus 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 nodes.
- , .
- Leaf split copies up, inner split moves up; delete borrows or merges.
- Keys: to .
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)