adding range restriction capability to dynamic data structure

32
Adding Range Restriction Capability to Dynamic Data Structure Based on work by Dan E. Willard And George S. Lueker Ohad Shacham Jan 2002

Upload: barney

Post on 14-Jan-2016

28 views

Category:

Documents


1 download

DESCRIPTION

Adding Range Restriction Capability to Dynamic Data Structure. Ohad Shacham Jan 2002. Based on work by Dan E. Willard And George S. Lueker. Agenda. Background – decomposable searching problems, range restriction. Bounded balanced trees. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Adding Range Restriction Capability       to Dynamic Data Structure

Adding Range Restriction Capability to Dynamic Data Structure

Based on work by Dan E. Willard And George S. Lueker

Ohad Shacham Jan 2002

Page 2: Adding Range Restriction Capability       to Dynamic Data Structure

Agenda

Background – decomposable searching problems, range restriction.

Bounded balanced trees. Adding range restriction capability to dynamic data

structure that gives amortized update time but does not guarantee worst case update time.

Comparison of some types of balanced trees. Modify the range restriction transformation as to

guarantee worst case time for each operation.

Page 3: Adding Range Restriction Capability       to Dynamic Data Structure

Background

Decomposable searching problems: A searching problem is decomposable if the response to a query asking the relation of new object ‘x’ to set F can be written as Q(x,F) = q(x,f), f F where is a commutative associative operator.

Range restriction: constraint a query to a specific group of records according to their range component.

Page 4: Adding Range Restriction Capability       to Dynamic Data Structure

Bounded Balanced Trees

Rank of node x, written rank(x) is

1 + #(Nodes that descend from x). Balance of node x, written ρ(x) is the ratio of rank of

the left child of x to rank(x). Node x is α balanced if ρ(x) [α, 1 – α]. Binary Search Tree is said to be Bounded Balanced

Tree with parameter α, or BB(α), if all nodes in the tree are α balanced.

The height of BB(α) for some positive α is O(logn).

Page 5: Adding Range Restriction Capability       to Dynamic Data Structure

Balance(x); Without loss of generality assume ρ(x) < α; Let y be the right child of x; if ρ(y) < γ

Perform the single rotation; else

Perform the double rotation;

Single rotation

Double rotation

X:

Y:

X:

Y:

Z:

X:

X:

Y:

Y:

Z:

Page 6: Adding Range Restriction Capability       to Dynamic Data Structure

Adding Range Restriction Capability With Good Total Update Time.

Given dynamic data structure D with complexity measures: – Ū(n) - amortized update time.– S(n) - space complexity.– Q(n) - worst case query time.

We can produce a corresponding data structure D’ with range restriction capabilities with complexity measures:– Ū’(n) = Ū(n)log(n).– S’(n) = S(n)log(n).– Q’(n) = Q(n)log(n).

Page 7: Adding Range Restriction Capability       to Dynamic Data Structure

Augmented Bounded Balance Tree

BB(α) tree which records stores at leaves only.

The records arrange according to their range component.

Each internal node will have precisely two children.

Page 8: Adding Range Restriction Capability       to Dynamic Data Structure

Each internal node contains:– field telling the largest leaf in it’s left sub tree.– field AUX that points to an instance of the original

data structure Containing all records that correspond to leaves descending it.

The BB(α) tree with the auxiliary fields call Augmented tree.

Page 9: Adding Range Restriction Capability       to Dynamic Data Structure

Query with range restriction

Performing a query on all the records whose range component between l and u.

Query(l,u,q,T)

R the set of nodes whose span is in [l,u] and whose parent span is not;

Query the sum, under over all r R, of the response of AUX(r) to query q;

Page 10: Adding Range Restriction Capability       to Dynamic Data Structure

Space and Query Complexities

The time for an execution of Query is O(Q(n)logn) – R contain O(logn) nodes.

The space complexity of augmented trees is O(S(n)logn) – The records in the auxiliary fields are disjoint.

Page 11: Adding Range Restriction Capability       to Dynamic Data Structure

Update the augmented tree

For any positive α < there exist γ and α’, with α’ < α that make the following true.

Let T be a sub tree, rooted at a node x,in which all nodes are α’ balanced.

Suppose that x is not α balanced.

Then after the call to BALANCE(x), all nodes in T that actively participated (the squares from the last figure) in the rebalancing will be α balanced.

2/21

Page 12: Adding Range Restriction Capability       to Dynamic Data Structure

Balance After Rotation

Rotation Type

VariableValueLower Bound

Upper Bound

Single

Double

'z

'y'x'y

'x yxx )1(

yxx

x

)1(

zyxx )1(

zyxx

x

)1(

zy

zy

1

)1(

'')2(

)1( ''

'

''' )1(

3''

'

)1(

)1(1 '

'

)1(

')1(

2')1)(1(

')1(

''

)'

)1(1

1(2

Page 13: Adding Range Restriction Capability       to Dynamic Data Structure

' 0.050000.052490.72500

0.100000.109890.70000

0.150000.171910.67500

0.200000.238050.65000

0.250000.280770.60961

Page 14: Adding Range Restriction Capability       to Dynamic Data Structure

β(x) = 2 max(0, ρ(x)–(1–α),α–ρ(x)).– Node is α balanced β(x) = 0.– Node is α’ balanced β(x) ≤ 2.

)'(1

Page 15: Adding Range Restriction Capability       to Dynamic Data Structure

INSERT(w,T)

Insert node w into T according to it’s range component;

Set the AUX field of the newly created parent of w to the copy of the AUX field of the sibling of w;for each ancestor x of w

insert the record represented by w into AUX(x);if any node x on the path from w to the root has β(x) > 2 then

PANIC: begin let x be the highest node with β(x) > 2;

rebuilt the tree rooted at x into a BB(1/3) tree; rebuilt all the auxiliary structures in the tree rooted at

x;end

for each node x on the path from w to the rootif β(x) > 1

ROTATE(X);

end

Page 16: Adding Range Restriction Capability       to Dynamic Data Structure

ROTATE(x)BALANCE(X);

for each node y whose set of descendant has been changed by this call to BALANCE

AUX(y) = an instance of data structure D representing the records descending from y;

end

Page 17: Adding Range Restriction Capability       to Dynamic Data Structure

There exist a constant ξ such that if a deletion or insertion is made in a tree and no rebalancing is done,then for each node in the tree the change in β(x)rank(x) is bounded above by ξ.– For instance 2 .

Suppose that the amortized complexity for insertions and deletions in D is Ū(n), where n is the maximum number of records ever presents. Then the amortized complexity Ū’(n) for INSERT and DELETE is O(Ū(n)log(n)).

)'(1

Page 18: Adding Range Restriction Capability       to Dynamic Data Structure

Comparison of Some Types of Balanced Trees

If a procedure analogous to INSERT is implemented using AVL trees, 2-3 trees or conventional bounded balanced trees, then the amortized complexity Ū’(n) for the resulting structure could be Ω(Ū(n)n).

The Reason for this is the number of rebalancing operation which causes many updates of the Auxiliary fields.

The Solution is to define various degrees of balance thus guarantee that when node was rebalanced it became sufficiently well balance that it did not need to be rebalanced again for a while.

Page 19: Adding Range Restriction Capability       to Dynamic Data Structure

Adding Range Restriction Capability With Good Total Update Time .

Main idea:Update the auxiliary field after rebalancing a little bit at a time during a sequence of several operations, instead of rebalancing all at once.

Page 20: Adding Range Restriction Capability       to Dynamic Data Structure

Disunified node - node that it’s auxiliary field is not fully rebuild.

Unified node - node that it’s auxiliary field is fully rebuild.

Partial augmented tree - augmented tree with disunified nodes.

Semi augmented tree - partial augmented tree that every disunified node in the tree has both children unified. (Our tree)

Page 21: Adding Range Restriction Capability       to Dynamic Data Structure

Near descendant of node x - node x, children, grand children and great grandchildren.

Eligible for rotation – node x is eligible for rotation if all of his near descendent are unified.

Page 22: Adding Range Restriction Capability       to Dynamic Data Structure

For each node we add the following field:– FLAG – Boolean flag that equals true if the

node is disunified, and false otherwise.– L – A list of records that are represented in

the auxiliary field.

The Space complexity remains the same.

The Query worst case time remains the same.

Page 23: Adding Range Restriction Capability       to Dynamic Data Structure

Procedure that add one new element to the auxiliary field:

FIXUP(y)let y’ and y’’ be the children of y;z an element of L(y’) U L(y’’) – L(y);add z to the data structure AUX(y);add z to L(y);if L(y’) U L(y’’) – L(y) = then FLAG(y) := false;

There is an implementation of FIXUP that runs in time bounded by O(1) + time for a single insertion in D.– Add DIFL and DIFR pointers for each internal

node.

Page 24: Adding Range Restriction Capability       to Dynamic Data Structure

INSERTB(w,T)

Insert node w into T according to it’s range component;

Set the AUX field of the newly created parent of w to the copy of the AUX field of the sibling of w;Set the L field of the newly created parent of w to the copy of the L field of the sibling of w; for each ancestor x of w dobegin

insert the record represented by w into AUX(x);insert w into L(x);

endif any node x on the path from w to the root has β(x) > 2 then

PANICB(x);for each node x on the path from w to the root

DoFIXUP(x);if x is eligible and β(x) > 1

ROTATEB(X);

end

Page 25: Adding Range Restriction Capability       to Dynamic Data Structure

PanicB(x)begin

let x be the highest node with β(x) > 2;

rebuilt the tree rooted at x into a BB(1/3) tree;

rebuilt all the auxiliary structures and the L lists in the tree rooted at x;

end

DoFIXUP(x)begin

do FIXUP operations on the disunified near descendant of x until either x is eligible or c FIXUPs have been done.

end

Page 26: Adding Range Restriction Capability       to Dynamic Data Structure

ROTATEB(x)begin

BALANCE(x);

for each node y whose set of descendants has been changed by this call to BALANCE

begin

FLAG(y) true;

AUX(y) the null structure for D;

L(y) ;

end

Page 27: Adding Range Restriction Capability       to Dynamic Data Structure

Several Problems Since now β(x) can be > 1 how can we be sure that

until β(x) will reach 2 it will become eligible ? The rebalancing causes several nodes to become

disunified. The rebalancing moves some nodes toward the root,

so that the node x may acquire new near descendents which may not be unified.

Solution: choose large enough constant C will overcome these problems, the coming lemmas will prove this.

Page 28: Adding Range Restriction Capability       to Dynamic Data Structure

Update – Complete execution of INSERTB or DELETEB.

t1,t2 – Points in time between successive updates. Min(x,t1,t2) – The minimum rank x had at any time

between t1 to t2. Max(x,t1,t2) – The maximum rank x had at any time

between t1 to t2. Update involving node v – Insertion or deletion of an

descendant of v. Node v is the focus of a rotation – If it plays the role

of the root in the rotation. Node v is the focus of a PANICB – If it plays the role

of the root in the PANICB.

Page 29: Adding Range Restriction Capability       to Dynamic Data Structure

There exists a constant ξ such that if s updates involving node x occur between t1 and t2, then β(x) will increase by no more than ξs/min(x,t1,t2).– Again ξ = 2 .

Suppose that from time t1 to time t2 at most

updates involving x occur. Then a node v can be the focus of at most one rotation or PANIC during any period of time between t1 and t2 over which it is a child or grandchild of x.

)'(1

2')2,1,min( ttx

Page 30: Adding Range Restriction Capability       to Dynamic Data Structure

Suppose that between t1 and t2 node x never actively participates in a rotation or PANIC. Suppose further that at most

updates occurred between t1 and t2. Then there can be no more than ten occasions when a child or grandchild of x is the focus of a rotation or PANIC during this time interval.

It is possible to choose C large enough in the algorithm INSERTB and DELETEB to guaranty that these algorithm never apply the PANIC block to a node of rank greater than max(3ξ,9).

2')2,1,min( ttx

Page 31: Adding Range Restriction Capability       to Dynamic Data Structure

Each insertion or deletion can be done employing O(logn) insertions and deletions operations on the auxiliary data structures and O(logn) additional time.

Page 32: Adding Range Restriction Capability       to Dynamic Data Structure

Let D be a dynamic data structure with complexity measures U,Q, and S.

Then we may produce a new structure D’ with range restriction capability the complexity of which is described by the primed functions below.

U’(n) = O(U(n)logn),

Q’(n) = O(Q(n)logn),

S’(n) = O(S(n)logn).