B-Tree
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.
