Improving scalability of the modified preorder tree traversal algorithm

后端 未结 3 829
星月不相逢
星月不相逢 2021-02-01 10:23

I\'ve been thinking about the modified preorder tree traversal algorithm for storing trees within a flat table (such as SQL).

One property I dislike about the standard a

3条回答
  •  你的背包
    2021-02-01 10:40

    You can split your table into two: the first is (node ID, node value), the second (node ID, child ID), which stores all the edges of the tree. Insertion and deletion then become O(tree depth) (you have to navigate to the element and fix what is below it).

    The solution you propose looks like a B-tree. If you can estimate the total number of nodes in your tree, then you can choose the depth of the tree beforehand.

提交回复
热议问题