Introduction to Scapegoat Trees
Explore the fundamentals of Scapegoat Trees, a type of binary search tree that self-balances through partial subtree rebuilding. Learn how these trees maintain logarithmic height, implement find, add, and remove operations efficiently, and how rebuilding keeps performance optimal.
We'll cover the following...
ScapegoatTree 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) ...