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+ 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. Point lookups descend one root-to-leaf path; range scans walk the leaf chain without ever climbing back up.

How B+ Tree: Introduction Works

  1. Internal nodes hold separator keys only (copies, no values).
  2. All key–value pairs live in leaf nodes.
  3. Leaves link to their right neighbour, forming a sorted chain.
  4. 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

  1. Root signposts: [20] — left means <20, right means ≥20.
  2. Left leaf chain: [10] → [20, 30] → [40].
  3. Find 30: root says right, leaf has it — 2 hops.
  4. Scan 20–40: land on 20, then walk the chain.

Output: Height 2 for 4 keys; range scans never revisit the root

📖 Introduction: this is an overview of the topic, so there's nothing to run here. Pick an operation from the side menu to see a live, step-by-step animation.
B+ Tree: Introduction
Signposts inside, values in chained leaves — the database index layout.
root signposts: [30]
10
20
leaf 0
30
40
leaf 1
Active leaf path Found key
B+ Tree: Introduction
Press ▶ Run to watch it step by step.
Python · B+ Tree in Code
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

TimeO(log n) point ops; O(log n + k) range scan for k keys
SpaceO(n)

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

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.