codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🗄️

DBMS

23 chapters

1Intro & 3-Schema Architecture2ER Model & Diagrams3Generalization, Specialization & Aggregation4Relational Model & Codd's Rules5Relational Algebra6Tuple & Domain Relational Calculus7SQL: DDL, DML, DCL8Advanced SQL (Joins, Aggregates)9Views, Triggers & Stored Procedures10Functional Dependencies11Normalization (1NF, 2NF, 3NF)12BCNF & Lossless Decomposition13Transaction Concepts & ACID14Conflict & View Serializability15Concurrency Control & Locks162-Phase Locking (2PL)17Timestamp-Based Protocols18Indexing (Primary, Clustering)19B-Trees & B+ Trees20Hashing Techniques in DBMS21Database Recovery Techniques22NoSQL Databases Overview23Data Warehousing Concepts
SubjectsDBMS

B-Trees & B+ Trees

Updated 2026-05-03
3 min read

B-Trees & B+ Trees

When you create an index in a database, the DBMS must choose a data structure to store that index. While standard Binary Search Trees (BSTs) are great for data sitting in RAM, they are disastrously slow for data stored on a hard disk.

Because disk reads happen in massive chunks (blocks/pages of 4KB to 8KB), we need a tree structure that is short, wide, and perfectly optimized for block-based storage. The industry standard solution is the B+ Tree.

1. Why not a Binary Search Tree?

In a Binary Search Tree, every node has at most 2 children. If you have 1 billion records, a perfectly balanced BST will have a height of about $\log_2(1,000,000,000) \approx 30$.

If the tree is stored on a hard disk, traversing from the root to a leaf requires visiting 30 different nodes. Because these nodes are scattered randomly across the disk platter, this requires 30 separate mechanical disk seeks. This is unacceptably slow.

2. The B-Tree

The B-Tree (Balanced Tree) was invented to solve this exact problem. Instead of a node holding 1 value and having 2 children, a B-Tree node is designed to perfectly fit inside a single 4KB disk block.

A single node might hold 100 values and have 101 children!

  • Because the branching factor is so massive, the tree is incredibly flat.
  • A B-Tree with 1 billion records might have a height of only 3 or 4.
  • Finding any record takes a maximum of 4 disk seeks.

3. The B+ Tree (The Industry Standard)

The B+ Tree is an improvement over the standard B-Tree and is the default indexing structure used by MySQL, PostgreSQL, Oracle, and SQL Server.

Differences from a standard B-Tree:

  1. Data is only at the leaves: In a B-Tree, data pointers can be stored in the internal routing nodes. In a B+ Tree, the internal nodes only contain routing keys. The actual pointers to the database rows are stored exclusively in the leaf nodes.
    • Advantage: Because internal nodes don't waste space holding data pointers, they can hold even more routing keys. This makes the tree even wider and shorter!
  2. Linked Leaves: In a B+ Tree, every leaf node contains a pointer to the next leaf node, forming a sequential Linked List at the bottom level.
    • Advantage: This makes Range Queries blazing fast. If you run SELECT * FROM Users WHERE Age BETWEEN 20 AND 30, the DBMS traverses down the tree once to find Age 20, and then simply walks horizontally across the linked list at the bottom until it hits Age 30. A standard B-Tree would require a costly full tree traversal for every single number.

Self-Balancing Guarantee: B+ Trees are fully self-balancing. No matter how many millions of rows you insert or delete, the distance from the root to every single leaf node is always exactly the same. Every query is guaranteed to perform consistently.



PreviousIndexing (Primary, Clustering)NextHashing Techniques in DBMS

Recommended Gear

Indexing (Primary, Clustering)Hashing Techniques in DBMS