# B-Tree

> The B-Tree is a self-balancing tree data structure commonly used in databases and file systems, allowing efficient multi-level search.

## What is a B-tree and why do databases use it?

The multi-level, balanced tree structure that keeps data sorted and allows searches, insertions and deletions in logarithmic time. Suitable for storage systems needing fast data access.

- Topic: Tree
- Type: data structure

## Common mistakes

- Confusing a B-tree with a binary tree; B-tree nodes hold many keys and many children.
- Expecting a B-tree index to speed up `LIKE '%term'`; a leading wildcard cannot use it.

## Interview questions

### B-tree vs binary search tree: what is the difference?

A B-tree node holds many keys and has many children, so the tree is short and wide. That means far fewer disk or page reads per lookup.

### What is the time complexity of a B-tree?

Search, insert and delete are O(log n). The number of node reads is about log base m of n, where m is the branching factor.

### B-tree vs B+ tree: which do databases use?

Most relational database indexes use B+ trees, where records sit in linked leaves, which makes range scans fast.

## Related cards

- [B+ Tree](https://wonderium.dev/algorithms/b-plus-tree.md)
- [Binary Search Tree](https://wonderium.dev/algorithms/binary-search-tree.md)
- [O(log n)](https://wonderium.dev/algorithms/o-log-n.md)
- [Relational Database](https://wonderium.dev/engineering/relational-db.md)
- [Databases](https://wonderium.dev/engineering/databases.md)

---

- Level: [Algorithms](https://wonderium.dev/algorithms.md)
- HTML version: https://wonderium.dev/algorithms/b-tree
- Last updated: 2026-11-25
