Vector clock: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
en>Monkbot
en>Habitmelon
m See also: Fix broken Riak Vector Clocks link
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
In [[computer science]], a '''scapegoat tree''' is a [[self-balancing binary search tree]], discovered by [[Arne Andersson (computer scientist)|Arne Andersson]]<ref name=anderson1>{{Cite conference | title=Improving partial rebuilding by using simple balance criteria | journal= Journal of Algorithms | first=Arne | last=Andersson | booktitle=Proc. Workshop on Algorithms and Data Structures | pages=393–402 | year=1989 | publisher=Springer-Verlag | doi=10.1007/3-540-51542-9_33}}</ref> and again by [[Igal Galperin]] and [[Ronald L. Rivest]].<ref name=galperin_rivest>{{Cite journal | first1=Igal | last1=Galperin | first2=Ronald L. | last2=Rivest | title=Scapegoat trees | journal=Proceedings of the fourth annual ACM-SIAM Symposium on Discrete algorithms | pages=165–174  | year=1993 | url=http://portal.acm.org/citation.cfm?id=313676 | postscript=<!-- Bot inserted parameter. Either remove it; or change its value to "." for the cite to end in a ".", as necessary. -->{{inconsistent citations}}}}</ref>  It provides worst-case [[big O notation|''O'']](log ''n'') lookup time, and ''O''(log ''n'') [[amortized analysis|amortized]] insertion and deletion time.
I woke up another day  and noticed - Now I have been single for a little while and following much bullying from pals I today locate myself opted for online dating. They assured me that there are plenty of normal, [http://www.pleasant.com/ pleasant] and entertaining visitors to meet up, therefore the pitch is gone by here!<br>My pals and family are magnificent  [http://lukebryantickets.flicense.com luke bryan 2014 tour dates] and hanging out together at pub gigabytes or meals is definitely a must. As I realize you can never own a decent dialogue against the sound I haven't ever been in to cabarets. I additionally got 2 quite adorable and undoubtedly  [http://lukebryantickets.iczmpbangladesh.org luke bryan 2014 tour schedule] cheeky canines who are constantly eager to meet up fresh folks.<br>I attempt to stay as toned as potential staying at the [http://www.adobe.com/cfusion/search/index.cfm?term=&fitness+center&loc=en_us&siteSection=home fitness center] several times a week. I enjoy my sports and strive to play or  [http://lukebryantickets.neodga.com luke bryan tour schedule 2014] see as many a potential. I'll frequently at Hawthorn matches being wintertime. Note: I have experienced the carnage of wrestling fits at stocktake sales, If you really contemplated buying an athletics I don't mind.<br><br><br><br>Also visit my web-site :: luke brian tickets ([http://lukebryantickets.lazintechnologies.com http://lukebryantickets.lazintechnologies.com/])
 
Unlike most other self-balancing binary search trees that provide worst case ''O''(log ''n'') lookup time, scapegoat trees have no additional per-node memory overhead compared to a regular [[binary search tree]]: a node stores only a key and 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.
 
==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, whereas an α of 0.5 would only match [[Binary tree#Types of binary trees|almost complete binary trees]].
 
A binary search tree that is α-weight-balanced must also be '''α-height-balanced''', that is
height(tree) <= log<sub>1/α</sub>(NodeCount)
 
Scapegoat trees are not guaranteed to keep α-weight-balance at all times, but are always loosely α-height-balance in that
height(scapegoat tree) <= log<sub>1/α</sub>(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, 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==
===Insertion===
 
Insertion is implemented with the same basic ideas as an [[Binary search tree#Insertion|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'') 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(sibling) + 1
But as:
size(inserted node) = 1.
The case is trivialized down to:
size[x+1] = size[x] + size(sibling) + 1
Where x = this node, x + 1 = parent and size(sibling) is the only function call actually required.
 
Once the scapegoat is found, the subtree rooted at the scapegoat is completely rebuilt to be perfectly balanced.<ref name=galperin_rivest/> This can be done in O(''n'') time by traversing the nodes of the subtree to find their values in sorted order and recursively choosing the median as the root of the subtree.
 
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, because these worst-case scenarios are spread out, insertion takes O(log ''n'') amortized 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:
 
<math>I(v) = max(|left(v) - right(v)| - 1, 0) \ </math>
 
Immediately after rebuilding a subtree rooted at ''v'', I(''v'') = 0.
 
'''Lemma:''' Immediately before rebuilding the subtree rooted at ''v'', <br />
<math>I(v) = \Omega (|v|) \ </math><br />
(<math>\Omega \ </math> is [[Big O Notation]].)
 
Proof of lemma:
 
Let <math>v_0</math> be the root of a subtree immediately after rebuilding.  <math>h(v_0) = log(|v_0| + 1) \ </math>.  If there are <math>\Omega (|v_0|)</math> degenerate insertions (that is, where each inserted node increases the height by 1), then <br />
<math>I(v) = \Omega (|v_0|) \ </math>,<br />
<math>h(v) = h(v_0) + \Omega (|v_0|) \ </math> and<br />
<math>log(|v|) \le log(|v_0| + 1) + 1 \ </math>.
 
Since <math>I(v) = \Omega (|v|)</math> before rebuilding, there were <math>\Omega (|v|)</math> insertions into the subtree rooted at <math>v</math> that did not result in rebuilding.  Each of these insertions can be performed in <math>O(log n)</math> time. The final insertion that causes rebuilding costs <math>O(|v|)</math>. Using [[aggregate analysis]] it becomes clear that the amortized cost of an insertion is <math>O(log n)</math>:
 
<math>{\Omega (|v|) O(\log{n}) + O(|v|) \over \Omega (|v|)} = O(\log{n}) \ </math>
 
===Deletion===
 
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
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 <math>n</math> elements and has just been rebuilt (in other words, it is a complete binary tree). At most <math>n/2 - 1</math> deletions can be performed before the tree must be rebuilt.  Each of these deletions take <math>O(\log{n})</math> time (the amount of time to search for the element and flag it as deleted).  The <math>n/2</math> deletion causes the tree to be rebuilt and takes <math>O(\log{n}) + O(n)</math> (or just <math>O(n)</math>) time.  Using aggregate analysis it becomes clear that the amortized cost of a deletion is <math>O(\log{n})</math>:
 
<math>
{\sum_{1}^{{n \over 2}} O(\log{n}) + O(n) \over {n \over 2}} =
{{n \over 2}O(\log{n}) + O(n) \over {n \over 2}} =
O(\log{n}) \
</math>
 
===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 tree]]s which have a worst-case time of O(''n''). The reduced node memory overhead compared to other self-balancing binary search trees can further improve [[locality of reference]] and caching.
 
==See also==
* [[Splay tree]]
* [[tree data structure|Trees]]
* [[Tree rotation]]
* [[AVL tree]]
* [[B-tree]]
* [[T-tree]]
* [[List of data structures]]
 
==References==
{{Reflist}}
 
==External links==
*[http://people.ksp.sk/~kuko/bak/index.html Scapegoat Tree Applet] by Kubo Kovac
*[http://cg.scs.carleton.ca/~morin/teaching/5408/refs/gr93.pdf Scapegoat Trees: Galperin and Rivest's paper describing scapegoat trees]
*[http://publications.csail.mit.edu/lcs/pubs/pdf/MIT-LCS-TR-700.pdf On Consulting a Set of Experts and Searching (full version paper)]
*[http://opendatastructures.org/versions/edition-0.1e/ods-java/8_Scapegoat_Trees.html Open Data Structures - Chapter 8 - Scapegoat Trees]
 
{{CS-Trees}}
 
{{DEFAULTSORT:Scapegoat Tree}}
[[Category:Binary trees]]

Latest revision as of 01:44, 13 January 2015

I woke up another day and noticed - Now I have been single for a little while and following much bullying from pals I today locate myself opted for online dating. They assured me that there are plenty of normal, pleasant and entertaining visitors to meet up, therefore the pitch is gone by here!
My pals and family are magnificent luke bryan 2014 tour dates and hanging out together at pub gigabytes or meals is definitely a must. As I realize you can never own a decent dialogue against the sound I haven't ever been in to cabarets. I additionally got 2 quite adorable and undoubtedly luke bryan 2014 tour schedule cheeky canines who are constantly eager to meet up fresh folks.
I attempt to stay as toned as potential staying at the fitness center several times a week. I enjoy my sports and strive to play or luke bryan tour schedule 2014 see as many a potential. I'll frequently at Hawthorn matches being wintertime. Note: I have experienced the carnage of wrestling fits at stocktake sales, If you really contemplated buying an athletics I don't mind.



Also visit my web-site :: luke brian tickets (http://lukebryantickets.lazintechnologies.com/)