Search code examples
algorithmtreeb-tree

CLRS B-Tree property lower and upper bound on number of keys of a node can contain


In CLRS Introduction to Algorithms : B-Tree definition a give property states that :

5.There are lower and upper bounds on the number of keys a node can contain. These bounds can be expressed in terms of a fixed integer t >= 2 called the minimum degree of the B-tree:

a. Every node other than the root must have at least t - 1 keys. Every internal node other than the root thus has at least t children. If the tree is nonempty, the root must have at least one key.

b. Every node can contain at most 2t - 1 keys. Therefore, an internal node can have at most 2t children. We say that a node is full if it contains exactly 2t - 1 keys.

It says that

t

is the minimum degree .

My question is that what t is counting, children node pointer or number of keys. and how property 5.b hold in that .

I have gone through Wikipedia definition of B-Tree ,2-Tree and 2-3-4 Tree and only found that no particular definition of Order of tree is given (As per Knuth order is equal to max number of child pointer of a node).


Solution

  • You seem a bit confused by the difference between Knuth order and CLRS degree so allow me to explain. Both the Knuth order and the CLRS degree measure: min <= children <= max, the minimum and maximum children, (min, max), each internal node in the tree is allowed to have. Both definitions agree that the min can't be less than max/2:

    Knuth Order, k |  (min,max)  | CLRS Degree, t
    ---------------|-------------|---------------
         0         |      -      |        –
         1         |      –      |        –
         2         |      –      |        –
         3         |    (2,3)    |        –
         4         |    (2,4)    |      t = 2
         5         |    (3,5)    |        –
         6         |    (3,6)    |      t = 3
         7         |    (4,7)    |        –
         8         |    (4,8)    |      t = 4
         9         |    (5,9)    |        –
         10        |    (5,10)   |      t = 5
    

    Key similarities / differences:

    • The Knuth order k is an index counting the maximum number of children. A Knuth order of k means every node must have a max = k, and a min = ceil(k/2). For example, (3,6) is a B-tree of Knuth order 6.
    • The CLRS degree t is an index counting the minimum number of children. A CLRS degree of t means every node must have a min = t and a max = 2t. For example, (3,6) is a B-tree of CLRS degree 3
    • In both definitions, it is the case the min = ceil(max / 2) and max = 2 * min.
    • In both definitions, it is the case that the number of keys is equal to the number of children minus one. So both the Knuth order and the CLRS degree are technically also counting minimum and maximum keys – as well as simultaneously counting the minimum and maximum children.

    • Knuth's definition allows trees (min,max), where max an is odd integer, but CLRS's definition ignores them. Any tree of the form (t, 2t-1) is invalid by CLRS's definition. For example a tree with (min,max) = (5,9) is a valid via Knuth's definition but invalid via CLRS's definition.


    Interesting asides:

    • Both definitions include 2-3-4 trees, which are trees with (min, max) = (2,4). It is a B-tree with Knuth order k = 4 and it's a CLRS B-tree with degree t = 2. These trees are closely related to Red-Black Trees.
    • Only Knuth's definition includes 2-3 trees, where (min, max) = (2,3). A 2-3 tree is a Knuth B-tree with Knuth order k = 3. It is not a valid CLRS B-tree. It's a shame that CLRS don't include this tree because they are closely related to AA trees.