algorithmdata-structurestreebinary-search-tree

Is there a balanced BST with each node maintain the subtree size?


Is there a balanced BST structure that also keeps track of subtree size in each node?

In Java, TreeMap is a red-black tree, but doesn't provide subtree size in each node.

Previously, I did write some BST that could keep track subtree size of each node, but it's not balanced.

The questions are:

BTW:

Possible appliation:


Solution

  • The Weight Balanced Tree (also called the Adams Tree, or Bounded Balance tree) keeps the subtree size in each node.

    This also makes it possible to find the Nth element, from the start or end, in log(n) time.

    My implementation in Nim is on github. It has properties:

    There are also implementations in Scheme and Haskell available.