Java TreeMap - 搜索时间复杂度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2864204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TreeMap - Search Time Complexity
提问by java_geek
What is the time complexity of a get() and put() in a TreeMap?
TreeMap 中 get() 和 put() 的时间复杂度是多少?
Is the implementation same as a Red-Black Tree?
实现与红黑树相同吗?
采纳答案by Daniel Renshaw
From here: http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html
从这里: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
此实现为 containsKey、get、put 和 remove 操作提供有保证的 log(n) 时间成本
回答by Bozho
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.
基于红黑树的 NavigableMap 实现。
此实现为 containsKey、get、put 和 remove 操作提供有保证的 log(n) 时间成本。算法是对 Cormen、Leiserson 和 Rivest 的算法简介中的算法的改编。