B-Tree vs B+ Tree Memory Usage

Venkatesh Kamalapathy
3 min readFeb 5, 2022

This blog helps to understand the difference in using B-Tree and B+ Tree in databases.

Photo by Jan Antonin Kolar on Unsplash

Let’s understand how each of the mentioned data structure works.

B-Tree vs B+ Tree

B-Tree

B-Trees stores both data and index on each node.

How Database B-Tree Indexing Works - DZone Database
B-Tree Memory Footprint

In such databases, due to bigger tuple, it is difficult to keep everything in memory. Hence some of the records are managed outside main memory by the use of data pointers.

B-Tree Memory

When some of the data gets stored on disk, there are few disadvantages.

  • Accessing disk will take longer as the searching requires numerous cycles of disk hops.
  • The search operations of external drives are generally not very efficient.
  • Memory management is poor when data has to be re-arranged after a search operation (add, delete, search).

B+ Tree

B+ tree eliminates the drawback B-tree, indexing by storing data pointers only at the leaf nodes of the tree. Thus, the structure of leaf nodes of a B+ tree is quite different from the structure of internal nodes of the B tree.

How Database B-Tree Indexing Works - DZone Database
B+ Tree Memory Footprint

It is significantly easy to store all the indexes in main memory as the data resides only on leaf level.

  1. In a B tree search keys and data are stored in all nodes. But in a B+ tree data is stored only in leaf nodes.
  2. Full scan of a B+ tree is very easy because all data are found in leaf nodes. Full scan of a B tree requires a full traversal which might require additional disk accesses.
  3. In a B tree, data may be found in leaf nodes or internal nodes. Deletion of internal nodes is very complicated. In a B+ tree, data is only found in leaf nodes. Deletion of leaf nodes is easy.
  4. Insertion in B tree is more complicated than B+ tree.
  5. B+ trees store redundant search keys but B tree has no redundant value.
  6. In a B+ tree, leaf node data is ordered as a sequential linked list but in a B tree the leaf node cannot be stored using a linked list. Many database systems’ implementations prefer the structural simplicity of a B+ tree.

--

--

Venkatesh Kamalapathy

A Polyglot Developer and a Competitive Programmer. Interested in web technologies, cloud computing and electronics.