Question: In chapter 14 we saw that we can augment a red-black tree of n nodes with an additional attribute at each node, the size, which
In chapter 14 we saw that we can augment a red-black tree of n nodes with an additional attribute at each node, the size, which is the number of (internal) nodes in the subtree rooted at x. We also saw that the size at a node can be computed using only the information stored in x, left(x), and right(x), and that we can maintain size at all nodes during insertion and deletion in O(log n) time. In particular, we can maintain size so that Insert(x) and Delete(x) are supported in O(log n) time. Write a new function on a red-black tree, Count(x), which returns the number of elements larger than x in the red-black tree. Your function should work even if x is not in the red-black tree. Show your function runs in O(log n) time.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
