Computational Complexity of TreeSet methods in Java

后端 未结 1 1100
忘掉有多难
忘掉有多难 2021-02-05 21:20

Is the computational complexity of TreeSet methods in Java, same as that of an AVLTree?

Specifically, I want to know the computational complexity of the following metho

1条回答
  •  攒了一身酷
    2021-02-05 21:54

    Operations which work on a single element are all O(ln n) comparisons except first and last which are O(1) comparisons or O(ln N) node search time.

    comparator(), iterator(), clear(), first(), isEMpty(), size(), last(), pollFirst(), pollLast() are O(1)

    add(), ceiling(), contains(), floor(), headSet(), higher(), lower(), remove(), subSet(), tailSet() are O(ln N)

    clone(), equals(), hashCode(), toArray() and toString() are O(n)

    0 讨论(0)
提交回复
热议问题