ArticleslgStudy

computer science

Scapegoat tree

Scapegoat tree is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Scapegoat tree rather than just read about it. In short: In computer science, a scapegoat tree is a self-balancing binary search tree, invented by Arne Andersson in 1989 and rediscovered by Igal Galperin and Ronald L. Rivest in 1993.

Key takeaways

  • Scapegoat tree belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Scapegoat tree to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Scapegoat tree from memory before moving on to harder problems.

Reference excerpt

In computer science, a scapegoat tree is a self-balancing binary search tree, invented by Arne Andersson in 1989 and rediscovered by Igal Galperin and Ronald L. Rivest in 1993. It provides worst-case O ( log ⁡ n ) {\displaystyle O(\log n)} lookup time (as expressed in big O notation, with n {\displaystyle n} as the number of entries) and O ( log ⁡ n ) {\displaystyle O(\log n)} amortized insertion and deletion time. Unlike most other self-balancing binary search trees which also provide worst case O ( log ⁡ n ) {\displaystyle O(\log n)} lookup time, scapegoat trees have no additional per-node memory overhead compared to a regular binary search tree: besides key and value, a node stores only two pointers to the child nodes. This makes scapegoat trees easier to implement and, due to data structure alignment, can reduce node overhead by up to one-third. Instead of the small incremental rebalancing operations used by most balanced tree algorithms, scapegoat trees rarely but expensively choose a "scapegoat" and completely rebuilds the subtree rooted at the scapegoat into a complete binary tree. Thus, scapegoat trees have O ( n ) {\displaystyle O(n)} worst-case update performance.

Theory A binary search tree is said to be weight-balanced if half the nodes are on the left of the root, and half on the right. An α-weight-balanced node is defined as meeting a relaxed weight balance criterion:

size(left) ≤ α*size(node) size(right) ≤ α*size(node)

Where size can be defined recursively as:

function size(node) is if node = nil then return 0 else return size(node->left) + size(node->right) + 1 end if end function

Even a degenerate tree (linked list) satisfies this condition if α=1, whereas an α=0.5 would only match almost complete binary trees. A binary search tree that is α-weight-balanced must also be α-height-balanced, that is

height(tree) ≤ floor(log1/α(size(tree)))

By contraposition, a tree that is not α-height-balanced is not α-weight-balanced. Scapegoat trees are not guaranteed to keep α-weight-balance at all times, but are always loosely α-height-balanced in that

height(scapegoat tree) ≤ floor(log1/α(size(tree))) + 1.

Violations of this height balance condition can be detected at insertion time, and imply that a violation of the weight balance condition must exist. This makes scapegoat trees similar to red–black trees in that they both have restrictions on their height. They differ greatly though in their implementations of determining where the rotations (or in the case of scapegoat trees, rebalances) take place. Whereas red–black trees store additional 'color' information in each node to determine the location, scapegoat trees find a scapegoat which isn't α-weight-balanced to perform the rebalance operation on. This is loosely similar to AVL trees, in that the actual rotations depend on 'balances' of nodes, but the means of determining the balance differs greatly. Since AVL trees check the balance value on every insertion/deletion, it is typically stored in each node; scapegoat trees are able to calculate it only as needed, which is only when a scapegoat needs to be found. Unlike most other self-balancing search trees, scapegoat trees are entirely flexible as to their balancing. They support any α such that 0.5 < α < 1. A high α value results in fewer balances, making insertion quicker but lookups and deletions slower, and vice versa for a low α. Therefore in practical applications, an α can be chosen depending on how frequently these actions should be performed.

Operations

Lookup Lookup is not modified from a standard binary search tree, and has a worst-case time of O ( log ⁡ n ) {\displaystyle O(\log n)} . This is in contrast to splay trees which have a worst-case time of O ( n ) {\displaystyle O(n)} . The reduced node memory overhead compared to other self-balancing binary search trees can further improve locality of reference and caching.

Insertion Insertion is implemented with the same basic ideas as an unbalanced binary search tree, however with a few significant changes. When finding the insertion point, the depth of the new node must also be recorded. This is implemented via a simple counter that gets incremented during each iteration of the lookup, effectively counting the number of edges between the root and the inserted node. If this node violates the α-height-balance property (defined above), a rebalance is required. To rebalance, an entire subtree rooted at a scapegoat undergoes a balancing operation. The scapegoat is defined as being an ancestor of the inserted node which isn't α-weight-balanced. There will always be at least one such ancestor. Rebalancing any of them will restore the α-height-balanced property. One way of finding a scapegoat, is to climb from the new node back up to the root and select the first node that isn't α-weight-balanced. Climbing back up to the root requires O ( log ⁡ n ) {\displaystyle O(\log n)} storage space, usually allocated on the stack, or parent pointers. This can actually be avoided by pointing each child at its parent as you go down, and repairing on the walk back up. To determine whether a potential node is a viable scapegoat, we need to check its α-weight-balanced property. To do this we can go back to the definition:

size(left) ≤ α*size(node) size(right) ≤ α*size(node)

However a large optimization can be made by realizing that we already know two of the three sizes, leaving only the third to be calculated. Consider the following example to demonstrate this. Assuming that we're climbing back up to the root:

size(parent) = size(node) + size(sibling) + 1

But as:

size(inserted node) = 1.

The case is trivialized down to:

size[x+1] = size[x] + size(sibling) + 1

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Scapegoat tree

Start with the simplest possible case. Write down what Scapegoat tree claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Scapegoat tree before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Scapegoat tree ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Scapegoat tree

In research
Scapegoat tree appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Scapegoat tree in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Scapegoat tree is common in secondary-school and first-year university syllabi. It links to neighbouring topics Amortized data structures, Binary trees, Search trees, so understanding it makes those chapters shorter.
In everyday life
Look for Scapegoat tree outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Scapegoat tree” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Scapegoat tree in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Scapegoat tree means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Scapegoat tree out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Scapegoat tree in simple terms?

In computer science, a scapegoat tree is a self-balancing binary search tree, invented by Arne Andersson in 1989 and rediscovered by Igal Galperin and Ronald L. Rivest in 1993.

Why does Scapegoat tree matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Scapegoat tree?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Scapegoat tree.

Tags

  • Amortized data structures
  • Binary trees
  • Search trees

Keep exploring