Algorithms/Data Structures
Updated on:
November 27, 2023

What is the B-tree?

A B-tree is a self-balancing tree data structure that maintains sorted data and allows efficient inserts, deletes and searches. B-trees keep data sorted and allow searches, sequential access, and insertions in logarithmic time.

B-trees are optimized for disk reads and writes where seek times matter. They are commonly used in databases and filesystems to organize records and blocks for efficient access based on key values.

B-trees use branching to store keys in sorted leaf pages while minimizing disk seeks. Internal nodes act as guides to navigate leaves. This allows fast lookup by key range, sequential range scans, and insertions with minimal disk I/O.

B-trees use techniques like interval arithmeticBloom filters, and related structures like skip lists to efficiently handle range queries, membership, and sorting. Variants like B+ trees optimize disk layout and caching for faster I/O performance. Overall, B-trees provide fast, robust data access on disk for sorted key-value data.

How does it work?

B-trees split up data into fixed-size blocks and store values in tree nodes. By enforcing a minimum and maximum number of child nodes, B-trees remain balanced on disk as they grow and shrink. Efficient disk block access patterns result.

B-trees grow recursively by splitting full nodes. Multiple key values are stored in nodes to reduce height.

Why is it important? Where is it used?

B-trees provide excellent read and write speeds for large keyed datasets on disk-based storage. They are ubiquitous indexing structures in databases, filesystems, and any system needing to store and retrieve ordered data efficiently. Indexing on B-trees scales well with large data.

B-trees are fundamental persistent storage data structures used everywhere sequential key access matters.


How is a B-tree different from a binary search tree?

B-trees allow multiple child nodes vs just two. They store multiple keys per node. The balancing rules maintain efficient disk access patterns.

What are the main operations supported by a B-tree?

  • Search - Logarithmic search for values.
  • Insert - Insert while maintaining sort order and balancing.
  • Delete - Delete nodes while rebalancing tree.
  • List keys in order - Enumerate sorted keys sequentially.

What are the advantages of using B-trees?

  • Efficient and scalable ordered key access on disk.
  • Logarithmic complexity for search, insert, delete.
  • Balanced structure minimizes disk reads.
  • Multiple keys per node improves space utilization.

What are some downsides of B-trees?

  • More complex to implement than binary trees.
  • Requires careful rebalancing on inserts/deletes.
  • Lower locality of reference due to node size.


Related Entries

Interval arithmetic

Interval arithmetic is a method of computing with sets of numbers rather than single values, representing uncertainty in calculations and accounting for rounding errors.

Bloom Filter

A Bloom filter is a probabilistic data structure used to test set membership that is space-efficient compared to storing the full set.

Probabilistic data structures

Probabilistic data structures are space and time efficient data structures that use randomized algorithms to provide approximate results to queries with strong guarantees.


Get early access to AI-native data infrastructure