views:

183

answers:

3

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

Is the implementation same as a Red-Black Tree?

+1  A: 

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.

Bozho
+1  A: 

Did you look in the documentation? It’s all there, you know. And in the first two paragraphs of the summary, no less.

Konrad Rudolph
+4  A: 

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

Daniel Renshaw