Do btrees and b + trees only make data on leaves?

Will trees b and trees b + only store data on leaves? I assume that they use their internal nodes to find the necessary data.

Is this the case or do they store data in each node?

+7
theory b-tree
source share
3 answers

The leafy "record" nodes contain

  • pointer (a node "sorting address") to a node at the next level down the tree
  • key value of the first (or last, depending on implementation) record in node

Such non-leafy β€œentries” are listed in key order, so when scanning (or binary search inside) a non-leaf node, it is known that the node at the next level down may contain the desired value.

Sheet node sheets contain complete data records: key value and everything else.

Therefore, β€œreal” data is contained only in leaf nodes, but non-leaf nodes contain only [copy] of key values. for a very small fraction of the data (this proportion depends on the average number of data records found in the node sheet).

This is shown in the following image from the Wikipedia article on B + Trees simple btree

The non-leaf node at the top (the only one in this simplified tree) contains only two entries without a node, each with a copy of the key value (bluish color) and a pointer to the corresponding node (gray color). This tree has only two levels, so the "entries" in the root directory of the node point to leaf nodes. You can imagine that there are additional levels (above the topmost tree shown below, call it "3-5 node"); if this were so, then the node above would contain (along with other similar entries) an entry with a key value of 3 with a pointer to a "3-5" node.
Also note that only key values ​​3 and 5 are contained in non-leaf nodes (i.e., not even all key values ​​are reproduced in non-leaf nodes).
BTW in this example, non-leaf nodes contain the key of the last record in the next node (it will also work if the first record is used instead, there is a slight difference in how the search logic is implemented).

The leaf nodes contain the key value (in bluish color) and the corresponding data record (d1, d2 ... are shown in gray). The red pointer shown at the end of each node leaf points to the next node leaf, that is, the one that contains the very next data record in key order; these pointers are useful for β€œscanning” a range of data records.

+7
source share

All data are in sheets.

Wiki on B + .

+1
source share

There is some confusion in BTrees and B + trees. B + Trees only store data on leaf nodes as pointers. This means that the data must be stored elsewhere. BTrees can store data on each node. Each has its own advantages and disadvantages. I noticed that some sites show BTrees just like B + Trees. In general, BTrees are better at holding actual data, and B + trees are much more efficient as indexes.

0
source share

All Articles