Search code examples
data-structurestreeb-tree

which is the exactly definition of 2-3 tree


Sorry,I can't post pictures, so I print them with keyboard.

                             [6:-]

               [2:4]                        [8:-]      

     [0:1]     [2:3]    [4:5]         [6:7]       [8:9]

this one is from 《data structure and algorithm》, it is the picture of 2-3 tree, you can see every data on father node must on their child node.

                             [50:90]

      [20:-]                 [70:-]                  [120:150]

[10:-]    [30:40]       [60:-]    [80:-]    [100:110]   [130:140]   [160:-]  

and this one is from another book called《data abstraction and problem solving with c++》, data on father node doesn't on their child node.

Which one is right?


Solution

  • These are both 2-3 trees, since the "2-3" just refers to the number of children each node has. But these trees have different more specific names.

    The first one, in which the parents copy keys from the children, is called a "B+ tree": https://en.wikipedia.org/wiki/B%2B_tree

    The second one, in which the parent keys are not copies, is called a "B tree": https://en.wikipedia.org/wiki/B-tree

    Note the there are usually values associated with the keys, and in the B+ tree, the internal nodes don't contain values.

    B+ trees are popular for database indexes backed by the file system. Because the internal nodes don't contain values, they can have higher fan-out, reducing the height of the tree and making access faster.

    Often the leaf nodes don't actually store values either -- they store pointers to the locations where the values are stored, and this conveniently gives the leaf nodes of a B+ tree exactly the same structure as the internal nodes.