TreeMap - Search Time Complexity

2020-08-10 08:12发布

What is the time complexity of a get() and put() in a TreeMap?

Is the implementation same as a Red-Black Tree?

2条回答
ら.Afraid
2楼-- · 2020-08-10 08:38

TreeMap is:

A Red-Black tree based NavigableMap implementation.

This implementation provides guaranteed log(n) time cost for the containsKey, get, put and remove operations. Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's Introduction to Algorithms.

查看更多
混吃等死
3楼-- · 2020-08-10 08:39

From here: http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html

This implementation provides guaranteed log(n) time cost for the containsKey, get, put and remove operations

查看更多
登录 后发表回答