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

前端 未结 5 1639
-上瘾入骨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:10

    Unfortunately, all trees exhibit their worst case scenario running times, and require rigid balancing techniques when data is entered in increasing order like that. Binary trees quickly turn into linked lists, etc.

    For typical B-Tree use cases (databases, filesystems, etc), you can typically count on your data naturally being more distributed, producing a tree more like your second example.

    Though if it is really a concern, you could hash each key, guaranteeing a wider distribution of values.

    for( i=1; i<8; ++i )
        tree.push(hash(i));
    

提交回复
热议问题