Why the search time for TreeSet is O(nlogn)?
https://softwareengineering.stackexchange.com/questions/334613
-
31-12-2020 - |
题
In my naive opinion it should be O(n) in worst case since Tree could get spindly and unbalanced.
解决方案
TreeSet is based on TreeMap, which is a Red-Black Tree implementation. Red-Black Trees are self-balancing binary search trees that guarantee O(log n)
performance for search, insert and delete operations.