Data Structures · Visualization
B+ Tree: Introduction
B+ Tree
A B+ tree is the B-tree remodelled for databases: keys are copied up into internal nodes as signposts, while ALL real values live in the leaves — and the leaves are chained left-to-right like a linked list. Time: O(log n) point ops; O(log n + k) range scan for k keys. Space: O(n).
Big-O: Point ops O(log n); range scan O(log n + k).
B+ Tree: Introduction
B+ TreeA B+ tree is the B-tree remodelled for databases: keys are copied up into internal nodes as signposts, while ALL real values live in the leaves — and the leaves are chained left-to-right like a linked list. Point lookups descend one root-to-leaf path; range scans walk the leaf chain without ever climbing back up.
How B+ Tree: Introduction Works
- Internal nodes hold separator keys only (copies, no values).
- All key–value pairs live in leaf nodes.
- Leaves link to their right neighbour, forming a sorted chain.
- Fan-out of hundreds keeps height at 2–4 for millions of rows.
B+ Tree: Introduction Worked Example
Input: Order-3 B+ tree holding keys 10, 20, 30, 40
- Root signposts: [20] — left means <20, right means ≥20.
- Left leaf chain: [10] → [20, 30] → [40].
- Find 30: root says right, leaf has it — 2 hops.
- Scan 20–40: land on 20, then walk the chain.
Output: Height 2 for 4 keys; range scans never revisit the root
Press ▶ Run to watch it step by step.
def insert(root, key):
leaf = descend(root, key) # follow signposts
leaf.keys.insert_sorted(key)
if len(leaf.keys) > MAX:
left, right, mid = split(leaf)
parent_insert(mid, left, right) # copy up
# splits cascade; root split grows height
# example: intro on [10, 20, 30, 40]B+ Tree: Introduction Time & Space Complexity
When to Use B+ Tree: Introduction
- The index behind InnoDB, PostgreSQL B-tree indexes and filesystems
- Range-heavy workloads: time series, sorted pagination, prefix scans
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.