I am trying to clarify some things related to the complexity of some TreeSet operations. The javadoc says:
"This implementation provides a guaranteed log (n) of time for basic operations (add, delete and contains)."
So far so good. My question is what happens with addAll (), removeAll (), etc. Here the javadoc for Set says:
"If the specified collection is also set, the addAll operation effectively modifies this set so that its value is the union of two sets."
Is it just an explanation of the logical result of the operation or a hint about complexity? I mean, if two sets are represented, for example, by red-black trees, it would be better to somehow join the trees than to "add" each element of one to the other.
In any case, is there a way to combine two TreeSets into one with O (logn) complexity?
Thanks in advance.: -)
java complexity-theory treeset red-black-tree
Andreas K.
source share