Introduction to Scapegoat Trees
Explore the fundamentals of Scapegoat Trees, a balanced binary search tree that maintains logarithmic height through partial subtree rebuilding. Understand how adding and removing nodes triggers balance restoration via scapegoat nodes, and learn the efficiency and implementation details of these operations in C++.
Scapegoat trees overview
Here, we study a binary search tree data structure, the ScapegoatTree. This structure is based on the common wisdom that, when something goes wrong, the first thing people tend to do is find someone to blame (the scapegoat). Once blame is firmly established, we can leave
the scapegoat to fix the problem.
A ScapegoatTree keeps itself balanced by partial rebuilding operations. During a partial rebuilding operation, an entire subtree is deconstructed and rebuilt into a perfectly balanced subtree. There are many ways of rebuilding a subtree rooted at node u into a perfectly balanced
tree. One of the simplest is to traverse u’s subtree, gathering all its nodes
into an array, a, and then to recursively build a balanced subtree using
a. If we let m = a.length/2, then the element a[m] becomes the root of the
new subtree, a get stored recursively in the left subtree and
...
A call to rebuild(u) takes ...