TreeMap - Search Time Complexity

↘锁芯ラ 提交于 2020-02-21 09:46:31

问题


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

Is the implementation same as a Red-Black Tree?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2864204/treemap-search-time-complexity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!