Is there a tree that can rank an object?

I encoded the Red Black binary statistics tree to get the rank of an arbitrary object comparable to other objects in the Red Black tree. I wonder if there is an API class that provides the same functionality.

It would be nice if a rank were assigned, the class has a function that returns an object of this rank inside the tree.

Note that Red-black BST allows these two operations in log (n) time, where n is the number of objects in the tree.

0
source share
4 answers

The standard API does not have an order statistics tree. TreeMapin particular, it does not have methods for searching for the rank of a key or finding a key by rank in O (log n) time.

( Apache Commons, Google Guava) .

+2

http://algs4.cs.princeton.edu/33balanced/RedBlackBST.java.html.

Prof. Sedgewick RedBlack, , , RedBlack BST. ( O (lgN)). ( , ). . ( java.util )

+1

. TreeMap<YourClassAsKey, Long>, TreeMap BST Long .

javadoc:

NavigableMap Red-Black.

-1

, TreeMap:

NavigableMap Red-Black. , , , .

log (n) containsKey, get, put remove. - , Cormen, Leiserson Rivest. .


, , , .

NavigableMap ( TreeMap) , floorKey ceilingKey.

-1

Source: https://habr.com/ru/post/1569428/


All Articles