From Wikipedia, the free encyclopedia
In computer science, a
is a tree data
structure that keeps data sorted and allows
searches, insertions, and deletions in
logarithmic amortized time. It is most
commonly used in databases and filesystems.
In B-trees, internal (non-leaf) nodes can have
a variable number of child nodes within some pre-defined range. When data is inserted or
removed from a node, its number of child nodes changes. In order to maintain the pre-defined
range, internal nodes may be joined or split. Because a range of child nodes is permitted, B-trees
do not need re-balancing as frequently as other self-balancing search trees, but may waste some
space, since nodes are not entirely full. The lower and upper bounds on the number of child nodes
are typically fixed for a particular implementation. For example, in a 2-3 B-tree (often simply
referred to as a
), each internal node may have only 2 or 3 child nodes.
A B-tree is kept balanced by requiring that all external nodes are at the same depth. This depth
will increase slowly as elements are added to the tree, but an increase in the overall depth is
nfrequent, and results in all leaf nodes being one more node further removed from the root.
B-trees have substantial advantages over alternative implementations when node access times far
exceed access times within nodes. This usually occurs when most nodes are in secondary storage
such as hard drives. By maximizing the number of child nodes within each internal node, the
height of the tree decreases, balancing occurs less often, and efficiency increases. Usually this
value is set such that each node takes up a full disk block or an analogous size in secondary
storage. While 2-3 B-trees might be useful in main memory, and are certainly easier to explain, if
the node sizes are tuned to the size of a disk block, the result might be a 257-513 B-tree.
A B-tree of order m (the maximum number of children for each node) is a tree which satisfies the
following properties :
1. Every node has at most m children.
2. Every node (except root and leaves) has at least m/2 children.
3. The root has at least 2 children if it is not a leaf node.
4. All leaves appear in the same level, and carry no information.
5. A non-leaf node with k children contains k – 1 keys
The B-tree's creators, Rudolf Bayer and Ed McCreight, have not explained what, if anything, the
stands for. The most common belief is that
, as all the leaf nodes are at the
same level in the tree.
may also stand for
, Branching Tree, or for Boeing, because they
were working for
Boeing Scientific Research Labs
at the time.
1 Node structures
A simple B tree example.