In what order should you insert a set of known keys into a B-Tree to get minimal height?

前端 未结 5 1641
-上瘾入骨i
-上瘾入骨i 2020-12-23 17:31

Given a fixed number of keys or values(stored either in array or in some data structure) and order of b-tree, can we determine the sequence of inserting keys that would gene

5条回答
  •  忘掉有多难
    2020-12-23 18:01

    To build a particular B-tree using Insert() as a black box, work backward. Given a nonempty B-tree, find a node with more than the minimum number of children that's as close to the leaves as possible. The root is considered to have minimum 0, so a node with the minimum number of children always exists. Delete a value from this node to be prepended to the list of Insert() calls. Work toward the leaves, merging subtrees.

    For example, given the 2-3 tree

           8
       4       c
     2   6   a   e
    1 3 5 7 9 b d f,
    

    we choose 8 and do merges to obtain the predecessor

       4      c
     2   6  a   e
    1 3 5 79 b d f.
    

    Then we choose 9.

       4     c
     2   6 a   e
    1 3 5 7 b d f
    

    Then a.

        4    c
     2    6    e
    1 3  5 7b d f
    

    Then b.

       4   c
     2   6   e
    1 3 5 7 d f
    

    Then c.

       4
     2   6  e
    1 3 5 7d f
    

    Et cetera.

提交回复
热议问题