Information about Scapegoat Tree

In computer science, a scapegoat tree is a self-balancing binary search tree, invented by Igal Galperin and Ronald L. Rivest. It provides worst-case O(log n) lookup time, and O(log n) amortized insertion and deletion time.

Unlike other self-balancing binary search trees that provide worst case O(log n) lookup time, scapegoat trees have no additional per-node overhead compared to a regular binary search tree. [1] This makes scapegoat trees easier to implement and, due to data structure alignment, can reduce node overhead by up to one-third.

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 is therefore defined as meeting the following conditions: size(left) <= α*size(node) size(right) <= α*size(node) Where size can be defined recursively as: function size(node) if node = nil return 0 else return size(node->left) + size(node->right) + 1 end

An α of 1 therefore would describe a linked list as balanced, where as an α of 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) <= log1/α(NodeCount)

Scapegoat trees are not guaranteed to keep α-weight-balance at all times, however are always loosely α-height-balance in that height(scapegoat tree) <= log1/α(NodeCount) + 1

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. The means of determining the balance differs greatly though, as 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

Insertion

Insertion is implemented very similarly to an unbalanced binary search tree, however with a few key 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) 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 optimisation can be made by realising that we already know two of the three sizes, leaving only the third having 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(brother) But as: size(inserted node) = 0. The case is trivialized down to: size[x+1] = size[x] + size(brother) Where x = this node, x + 1 = parent and size(brother) is the only function call actually required.

Once the scapegoat is found, a standard binary search tree rebalance operation is performed.

As rebalance operations take O(n) time dependent on the number of nodes of the subtree, insertion has a worst case performance of O(n) time, however amortized has O(log n) average time.

Sketch of proof for cost of insertion

Define the Imbalance of a node v to be the absolute value of the difference in size between its left node and right node minus 1, or 0, whichever is greater. In other words:

I(v) = max(|left(v) - right(v)| - 1, 0)

Immediately after rebuilding a subtree rooted at v, I(v) = 0.

Lemma: Immediately before rebuilding the subtree rooted at v, I(v) = Ω(|v|)

Proof of lemma:

Let v0 be the root of a subtree immediately after rebuilding. h(v0) = log(|v0| + 1). If there are Ω(|v0|) degenerate insertions (that is, where each inserted node increases the height by 1), then I(v) = Ω(|v0|), h(v) = h(v0) + Ω(|v0|) and log(|v|) ≤ log(|v0| + 1) + 1.

Since I(v) = Ω(|v|) before rebuilding, there were Ω(|v|) insertions into the subtree rooted at v that did not result in rebuilding. Each of these insertions can be performed in O(log n) time. The final insertion that causes rebuilding costs O(|v|). Using aggregate analysis it becomes clear that the amortized cost of an insertion is O(log n):

The deletion operation

Scapegoat trees are unusual in that deletion is easier than insertion. To enable deletion, scapegoat trees need to store an additional value with the tree data structure. This property, which we will call MaxNodeCount simply represents the highest achieved NodeCount. It is set to NodeCount whenever the entire tree is rebalanced, and after insertion is set to max(MaxNodeCount, NodeCount).

To perform a deletion, we simply remove the node as you would in a simple binary search tree, but if NodeCount <= MaxNodeCount / 2 then we rebalance the entire tree about the root, remembering to set MaxNodeCount to NodeCount.

This gives deletion its worst case performance of O(n) time, however it is amortized to O(log n) average time.

Sketch of proof for cost of deletion

Suppose the scapegoat tree has n elements and has just been rebuilt (in other words, it is a complete binary tree). At most n/2 - 1 deletions can be performed before the tree must be rebuilt. Each of these deletions take O(log n) time (the amount of time to search for the element and flag it as deleted). The n/2 deletion causes the tree to be rebuilt and takes O(log n) + O(n) (or just O(n)) time. Using aggregate analysis it becomes clear that the amortized cost of a deletion is O(log n):

Lookup

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

References

1. ^ Galperin, Igal & Ronald L. Rivest (1993), "Scapegoat trees", Proceedings of the fourth annual ACM-SIAM Symposium on Discrete algorithms: pp. 165-174, <[1]

Further reading

  • id="CITEREFAndersson1999">Andersson, Arne (1999), "General balanced trees", Journal of Algorithms 30: pp. 1-28

    See also

    External links

    Computer science, or computing science, is the study of the theoretical foundations of information and computation and their implementation and application in computer systems.
    ..... Click the link for more information.
    In computer science, a self-balancing binary search tree or height-balanced binary search tree is a binary search tree that attempts to keep its height, or the number of levels of nodes beneath the root, as small as possible at all times, automatically.
    ..... Click the link for more information.

    ..... Click the link for more information.
    In computational complexity theory, big O notation is often used to describe how the size of the input data affects an algorithm's usage of computational resources (usually running time or memory).
    ..... Click the link for more information.
    amortized analysis refers to finding the average running time per operation over a worst-case sequence of operations. Amortized analysis differs from average-case performance in that probability is not involved; amortized analysis guarantees the time per operation over
    ..... Click the link for more information.
    binary search tree (BST) is a binary tree data structure which has the following properties:
    • Each node has a value.
    • A total order is defined on these values.
    • The left subtree of a node contains only values less than the node's value.

    ..... Click the link for more information.

    ..... Click the link for more information.
    A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science, typically used to implement associative arrays. The original structure was invented in 1972 by Rudolf Bayer who called them "symmetric binary B-trees", but acquired its
    ..... Click the link for more information.
    In computer science, an AVL tree is a self-balancing binary search tree, and the first such data structure to be invented. In an AVL tree the heights of the two child subtrees of any node differ by at most one, therefore it is also called height-balanced.
    ..... Click the link for more information.
    In computational complexity theory, big O notation is often used to describe how the size of the input data affects an algorithm's usage of computational resources (usually running time or memory).
    ..... Click the link for more information.
    A splay tree is a self-balancing binary search tree with the additional unusual property that recently accessed elements are quick to access again. It performs basic operations such as insertion, look-up and removal in O(log(n)) amortized time.
    ..... Click the link for more information.
    A splay tree is a self-balancing binary search tree with the additional unusual property that recently accessed elements are quick to access again. It performs basic operations such as insertion, look-up and removal in O(log(n)) amortized time.
    ..... Click the link for more information.


This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus


page counter