CS With NehalCS With Nehal

B+ Tree

Insert, delete, search in a B+ tree visualiser

Tree Properties
Max Children: 3Min Children: 2Max Keys: 2Min Keys: 1
Tree initialized. Select degree and enter a number.
Empty
History: 1 / 1
Animation Speed - 1200ms

About This Simulation

This B+ tree simulator lets you choose the order of the tree, insert and delete keys, and watch nodes split, merge and borrow keys while the tree stays balanced.

Features

  • Choose the order (maximum number of children) of the tree
  • Insert, delete and search keys
  • Node splits, merges and redistribution shown step by step
  • Linked leaf nodes for range queries
  • Pan, zoom and fullscreen view for large trees

Explanation

A B+ tree is a balanced search tree in which every key is stored in the leaf nodes, internal nodes only hold copies of keys that guide the search, and the leaves are linked together in sorted order. All leaves are at the same depth.

How it works

  1. Search: start at the root and follow the child pointer whose key range contains the target until you reach a leaf.
  2. Insert: add the key to the correct leaf in sorted order. If the leaf overflows, split it into two and copy the first key of the new right leaf up into the parent.
  3. If an internal node overflows, split it and move its middle key up. If the root splits, the tree grows one level taller.
  4. Delete: remove the key from its leaf. If the leaf has too few keys, borrow a key from a sibling or merge with it, and update the parent.
  5. Range query: find the first key with a normal search, then follow the leaf links to the right.

Why it matters

B+ trees are the index structure used by most relational databases (MySQL InnoDB, PostgreSQL, SQL Server) and file systems, because their high fan-out keeps the tree shallow and minimises disk reads. They are a key topic in database courses such as CSE370.

Frequently Asked Questions

What is the difference between a B tree and a B+ tree?

In a B tree, keys and data can be stored in any node. In a B+ tree, all data is in the leaves, internal nodes only guide the search, and the leaves are linked, which makes range queries and sequential scans much faster.

What is the order of a B+ tree?

The order is the maximum number of children an internal node can have. A node of order m holds at most m − 1 keys, and every node except the root must be at least half full.

What is the time complexity of search in a B+ tree?

O(log n) with a base equal to the fan-out, so search, insert and delete all take O(log_m n) node visits. With a large order, even millions of keys need only 3 or 4 levels.

Why do databases use B+ trees for indexing?

Each node fits a disk page and holds many keys, so the tree is very shallow and needs few disk reads. Linked leaves make range queries such as BETWEEN and ORDER BY efficient.

Topics covered

  • B+ Tree
  • Database Indexing
  • Node Splitting
  • Node Merging and Redistribution
  • Balanced Search Trees
  • Range Queries

Tags

  • b plus tree
  • index
  • insert
  • delete
  • order

Related Simulations

Acknowledgements

The Person Behind This Simulation

This simulation would not have been possible without his valuable contributions and support. We sincerely appreciate his time, effort, and dedication to the project.

Tahsin Uddin Labib

Tahsin Uddin Labib

  • 4th Year CS Undergraduate Student | BRAC University