ArticleslgStudy

computer science

B+ tree

B+ tree is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand B+ tree rather than just read about it. In short: A B+ tree is an m-ary tree with a variable but often large number of children per node. A B+ tree consists of a root, internal nodes, and leaves.

B+ tree — main illustration
B+ tree — illustration

Key takeaways

  • B+ tree belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect B+ tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of B+ tree from memory before moving on to harder problems.

Reference excerpt

A B+ tree is an m-ary tree with a variable but often large number of children per node. A B+ tree consists of a root, internal nodes, and leaves. The root may be either a leaf or a node with two or more children. A B+ tree can be viewed as a B-tree in which each node contains only keys (not key–value pairs), and to which an additional level is added at the bottom with linked leaves. The primary value of a B+ tree is in storing data for efficient retrieval in a block-oriented storage context—in particular, filesystems. This is primarily because unlike binary search trees, B+ trees have very high fanout (number of pointers to child nodes in a node, typically on the order of 100 or more), which reduces the number of I/O operations required to find an element in the tree.

History

There is no single paper introducing the B+ tree concept. Instead, the notion of maintaining all data in leaf nodes is repeatedly brought up as an interesting variant of the B-tree, which was introduced by R. Bayer and E. McCreight. Douglas Comer notes in an early survey of B-trees (which also covers B+ trees) that the B+ tree was used in IBM's VSAM data access software, and refers to an IBM published article from 1973.

Structure

Pointer structure

As with other trees, B+ trees can be represented as a collection of three types of nodes: root, internal (a.k.a. interior), and leaf. In B+ trees, the following properties are maintained for these nodes:

If ki exists in any node in a B+ tree, then ki-1 exists in that node where i≥1. All leaf nodes have the same number of ancestors (i.e., they are all at the same depth). The pointer properties of nodes are summarized in the tables below:

K: Maximum number of potential search keys for each node in a B+ tree. (this value is constant over the entire tree). pi: The pointer at the zero-based node index i. ki: The search key at the zero-based node index i.

Node bounds The node bounds are summarized in the table below:

Intervals in internal nodes

By definition, each value contained within the B+ tree is a key contained in exactly one leaf node. Each key is required to be directly comparable with every other key, which forms a total order. This enables each leaf node to keep all of its keys sorted at all times, which then enables each internal node to construct an ordered collection of intervals representing the contiguous extent of values contained in a given leaf. Internal nodes higher in the tree can then construct their own intervals, which recursively aggregate the intervals contained in their own child internal nodes. Eventually, the root of a B+ Tree represents the whole range of values in the tree, where every internal node represents a subinterval. For this recursive interval information to be retained, internal nodes must additionally contain m−1 copies of keys li for i∈[1,m−1] representing the least element within the interval covered by the child with index i (which may itself be an internal node, or a leaf). Where m represents the actual number of children for a given internal node.

Characteristics The order or branching factor b of a B+ tree measures the capacity of interior nodes, i.e. their maximum allowed number of direct child nodes. This value is constant over the entire tree. For a b-order B+ tree with h levels of index:

The maximum number of records stored is nmax=bh−bh−1 {bh−1 is subtracted to account for the next pointers which do not point to data records but instead point to the next leaf node} The minimum number of records stored is nmin=2⌈b2⌉h−1−2⌈b2⌉h−2 The minimum number of keys is nkmin=2⌈b2⌉h−1−1 The maximum number of keys is nkmax=bh−1 The space required to store the tree is O(n) Inserting a record requires O(logbn) operations Finding a record requires O(logbn) operations Removing a (previously located) record requires O(logbn) operations Performing a range query with k elements occurring within the range requires O(logbn+k) operations The B+ tree structure expands/contracts as the number of records increases/decreases. There are no restrictions on the size of B+ trees. Thus, increasing usability of a database system. Any change in structure does not affect performance due to balanced tree properties. The data is stored in the leaf nodes and more branching of internal nodes helps to reduce the tree's height, thus, reduce search time. As a result, it works well in secondary storage devices. Searching becomes extremely simple because all records are stored only in the leaf node and are sorted sequentially in the linked list. We can retrieve range retrieval or partial retrieval using B+ tree. This is made easier and faster by traversing the tree structure. This feature makes B+ tree structure applied in many search methods.

Algorithms

Search We are looking for a value k in the B+ Tree. This means that starting from the root, we are looking for the leaf which may contain the value k. At each node, we figure out which internal node we should follow. An internal B+ Tree node has at most m≤b children, where every one of them represents a different sub-interval. We select the corresponding child via a linear search of the m entries, then when we finally get to a leaf, we do a linear search of its n elements for the desired key. Because we only traverse one branch of all the children at each rung of the tree, we achieve O(log⁡N) runtime, where N is the total number of keys stored in the leaves of the B+ tree.

function search(k, root) is let leaf = leaf_search(k, root) for leaf_key in leaf.keys(): if k = leaf_key: return true return false

function leaf_search(k, node) is if node is a leaf: return node let p = node.children() let l = node.left_sided_intervals() assert |p|=|l|+1 let m = p.len() for i from 1 to m - 1: if k≤l[i]: return leaf_search(k, p[i]) return leaf_search(k, p[m])

Note that this pseudocode uses 1-based array indexing.

… excerpt ends here. Continue reading the full article.

Illustrations

B+ tree: A simple B+ tree example linking the keys 1–7 to data values d1-d7. The linked list (red) allows rapid in-order traversal. This particular tree's branching factor is b=4. Both keys in leaf and internal nodes are colored gray here.
A simple B+ tree example linking the keys 1–7 to data values d1-d7. The linked list (red) allows rapid in-order traversal. This particular tree's branching factor is b=4. Both keys in leaf and internal nodes are colored gray here.
B+ tree: B+ tree deletion
B+ tree deletion

Worked examples

Example 1 — a first encounter with B+ tree

Start with the simplest possible case. Write down what B+ tree claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to B+ tree before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about B+ tree ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of B+ tree

In research
B+ tree appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses B+ tree in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
B+ tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1972 in computing, B-tree, Computer-related introductions in 1972, so understanding it makes those chapters shorter.
In everyday life
Look for B+ tree outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “B+ tree” →

How to study B+ tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what B+ tree means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain B+ tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is B+ tree in simple terms?

A B+ tree is an m-ary tree with a variable but often large number of children per node. A B+ tree consists of a root, internal nodes, and leaves.

Why does B+ tree matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study B+ tree?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on B+ tree.

Tags

  • 1972 in computing
  • B-tree
  • Computer-related introductions in 1972

Keep exploring