Concatenating red-black trees

后端 未结 4 1825
迷失自我
迷失自我 2021-01-31 10:22

The OCaml standard library has a wonderful Set implementation that uses a very efficient divide-and-conquer algorithm to compute the union of two sets.

4条回答
  •  暖寄归人
    2021-01-31 11:11

    Can do better than O(log^2(n)) when concatenating and not augmenting the tree with height information in each node. You can concatenate in 2* [log(n1) + log(n2)] where n1 and n2 represent the number of nodes in the trees you are concatenating. After you compute the height in O(log(n)), use the Balance information in each node when going down the tree to find the right concatenation point!

提交回复
热议问题