I need a simple augmentation to support median/order statistic queries in O(log log n) time,without increasing the time for other operations.

  • 1
    $\begingroup$ ps: the reason that this doesn't look like a research-level question is that this looks like a standard exercise where the standard technique of augmenting data structures like BST for median should work. $\endgroup$
    – Kaveh
    Apr 28, 2013 at 20:11
  • 1
    $\begingroup$ I am not saying that it is a major research level question... but the augmentation is different then the any bst implementation, since at each level there are O(root(n)) children. $\endgroup$
    – Vk1
    Apr 29, 2013 at 14:11

1 Answer 1


I agree with Kaveh that this looks like an exercise, but I disagree that adapting the idea of rank-augmented binary search trees is the way to solve it. And 2.5 years later there should be no issue with accidentally spoiling someone's homework assignment.

The trick is to maintain, separately from the VEB-tree, the value of the median, and the total number of elements in the tree (from which you can also calculate the rank of the median value that you're storing). Then, when you insert or delete in the VEB-tree, you can compare the changed value to the median you are storing to determine how the change affects its rank. If this change causes it to stop being the median, then the new median is only a successor or predecessor query away, and those sorts of queries are what the VEB-tree is good at.

Unlike rank-augmented binary search trees, I don't know of a good way to do more general queries for finding the kth smallest element in a VEB-tree.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.