简体   繁体   中英

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 ? 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 . 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

Use a TreeMap . It is backed by a Red-Black tree so it's access time is O(logN) (my emphasis on quote bellow)

public class TreeMap
extends AbstractMap implements
NavigableMap, Cloneable, Serializable

A Red-Black tree based NavigableMap implementation. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM