Computational complexity of TreeSet operations in Java?

后端 未结 4 1449
暗喜
暗喜 2021-01-04 17:43

I am trying to clear up some things regarding complexity in some of the operations of TreeSet. On the javadoc it says:

\"This implementation provides

4条回答
  •  借酒劲吻你
    2021-01-04 18:06

    You could imagine how it would be possible to optimize special cases to O(log n), but the worst case has got to be O(m log n) where m and n are the number of elements in each tree.

    Edit:

    http://net.pku.edu.cn/~course/cs101/resource/Intro2Algorithm/book6/chap14.htm

    Describes a special case algorithm that can join trees in O(log(m + n)) but note the restriction: all members of S1 must be less than all members of S2. This is what I meant that there are special optimizations for special cases.

提交回复
热议问题