[英]Red Black tree or AVL tree implementation in Java
Is there any Red Black Tree
/ AVL Tree data
structure implementation in Java collections/Guava/Apache Commons library ? Java集合/ Guava / Apache Commons库中是否有任何
Red Black Tree
/ AVL Tree data
结构实现? If yes , can you point them to me . 如果是的话,你能指点我吗? Basically I am looking for a data structure where the queries should happen in O(lg n) time .
基本上我正在寻找一种数据结构,其中查询应该在O(lg n)时间内发生。 There will also be some updates to the data structure but not quite as often as the queries.
数据结构也会有一些更新,但不像查询那样频繁。
Basically I am looking for a data structure where the queries should happen in O(lg n) time
基本上我正在寻找一种数据结构,其中查询应该在O(lg n)时间内发生
Use a TreeMap . 使用TreeMap 。 It is backed by a Red-Black tree so it's access time is
O(logN)
(my emphasis on quote bellow) 它由红黑树支持,所以它的访问时间是
O(logN)
(我强调引用下面的文章)
public class TreeMap
公共类TreeMap
extends AbstractMap implements扩展AbstractMap实现
NavigableMap, Cloneable, SerializableNavigableMap,Cloneable,Serializable
A Red-Black tree based NavigableMap implementation.
基于红黑树的NavigableMap实现。 The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.
地图根据其键的自然顺序进行排序,或者根据使用的构造函数在地图创建时提供的比较器进行排序。
This implementation provides guaranteed log(n) time cost for the containsKey, get, put and remove operations.
此实现为containsKey,get,put和remove操作提供了有保证的log(n)时间成本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.