3.29
In each node of a binary tree store the sub tree sum for the left sub tree.
- Add : while descending the tree to the left update the sub tree sum by adding the value
-
Insert
: same as add, only now we have to add a new node too. To guaranty
- Delete : When the deleted element has at most 1 child, we only need to update the nodes ancestors. If there are two children, we also need to update elements on the path between the deleted element and it's successor. (The element with which we will swap it before deleting.)
- Partial sum : With the left sub tree sum values stored in the nodes this operation only involves searching for the element with the specified key, and summing sub tree sums along the way.
Back to
Chapter 3