java_geek
java_geek

Reputation: 18045

TreeMap - Search Time Complexity

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

Is the implementation same as a Red-Black Tree?

Upvotes: 23

Views: 29012

Answers (2)

Daniel Renshaw
Daniel Renshaw

Reputation: 34187

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

Upvotes: 38

Bozho
Bozho

Reputation: 597254

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.

Upvotes: 11

Related Questions