Concatenating red-black trees

后端 未结 4 1761
迷失自我
迷失自我 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:12

    Since you seem be talking about Concatenate + adding onto the end, it seems like you have the following problem:

    Given two red-black trees T1 and T2, such that keys of T1 <= keys of T2,
    find union of the two.
    

    This is called the join operation on the trees and in this case, it is possible to do the join of the trees in O(log n) time, check out: http://www.cs.tau.ac.il/~wein/publications/pdfs/rb_tree.pdf

    Also check out: http://net.pku.edu.cn/~course/cs101/resource/Intro2Algorithm/book6/chap14.htm, Problem 14.2.

提交回复
热议问题