Date post: | 04-Apr-2018 |
Category: |
Documents |
Upload: | sirc-ann-ares |
View: | 216 times |
Download: | 0 times |
of 17
7/29/2019 Augmented Data Structure
1/17
Augmented Data Structures
Associating further information with the nodes of a data structure.
Dynamic Order-Statistics Trees
Abstract data type dynamic order-statistics set:
INSERT SEARCH DELETE RANK SELECT
RANK(S,x) computes the rank ofx in S, i.e., |{s S: s x}|.
SELECT(S,k) computes the k-th smallest element in S.
1
7/29/2019 Augmented Data Structure
2/17
Implementation: Balanced binary search tree with additional infor-
mation stored at each node v: The number size(v) is the number of
internal nodes in the subtree rooted at v.
size(v) = size(lc(v)) + size(rc(v)) + 1
Here and later on, lc(v) and rc(v) denote the left and right child of a node v, respectively.
size(v) can be updated during insertion and deletion in O(log n) time.
46 42
89 89
59
4217
28
1728
2
7/29/2019 Augmented Data Structure
3/17
SELECT is implemented using SELECT(v,k), which returns the k-thsmallest key in the subtree rooted at v.
SELECTNODE(v,k)
1 r size(lc(v)) + 12 if r= k3 then return v
4 else ifr> k
5 then return SELECTNOD E(lc(v),k)6 else return SELECTNOD E(rc(v),k r)
3
7/29/2019 Augmented Data Structure
4/17
NODE RANK(T,v) computes the rank of a node v in an inorder traver-sal of tree T. In order to compute the rank of key x, search for the
node w containing x and call NODERANK(T,w).
NODE RAN K(T,v)
1 r size(lc(v)) + 12 w v
3while
(w = root(T))4 do ifw = rc(parent(w))5 then r r+ size(lc(parent(w)))+ 16 w parent(w)7 return r
4
7/29/2019 Augmented Data Structure
5/17
Theorem: Operations SEARCH, INSERT, DELETE, SELECT, and
RANK in an order-statistics tree storing n elements take time O(log n)each.
5
7/29/2019 Augmented Data Structure
6/17
Interval Overlap
Given a set of closed intervals
I= {[x1,x1], [x2,x
2], . . . , [xn,x
n]}
check whether a closed query interval
[q,q]
overlaps any of the intervals in I.
All cases:
6
7/29/2019 Augmented Data Structure
7/17
Application:
Intersection detection of axis-parallel rectangles using plane-sweep
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 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1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 10 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 01 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1
0 0 0 0 0 00 0 0 0 0 00 0 0 0 0 0
0 0 0 0 0 0
1 1 1 1 1 11 1 1 1 1 11 1 1 1 1 1
1 1 1 1 1 1
Sweep a horizontal line from top to bottom.Maintain the intersection intervals of the rectangles and the sweep
line in a data structure appropriate for interval overlap queries.
Check for overlap at the upper sides of the rectangles.
7
7/29/2019 Augmented Data Structure
8/17
Sweep line reaches an upper side:
00000000
00000000
00000000
00000000
00000000
11111111
11111111
11111111
11111111
11111111
?
OVERLAP(I) INSERT(I)
8
7/29/2019 Augmented Data Structure
9/17
Sweep line reaches a lower side:
00000000
00000000
00000000
00000000
00000000
11111111
11111111
11111111
11111111
11111111
DELETE(I)
9
7/29/2019 Augmented Data Structure
10/17
Implementation:
Balanced binary search tree for the intervals ordered according to left
endpoints xi.
10
7/29/2019 Augmented Data Structure
11/17
maxright(v
Additional information stored at each node v:
maxright(v) is the largest right endpoint of theintervals stored in the subtree rooted at v.
11
7/29/2019 Augmented Data Structure
12/17
FIN DOVERLAPPINGINTERVAL(T, [q,q])
1 v root(T)2 while (v is not a leaf and [q,q] does not overlap interval(v))3 do if(lc(v) exists and maxright(lc(v)) q)4 then v lc(v)5 else v rc(v)
12
7/29/2019 Augmented Data Structure
13/17
FIN DOVERLAPPINGINTERVAL(T, [q,q])
1 v root(T)2 while (v is not a leaf and [q,q] does not overlap interval(v))3 do if(lc(v) exists and maxright(lc(v)) q)4 then v lc(v)5 else v rc(v)
Lemma:
1. If line 5 is executed, then vs left subtree contains no interval
that overlaps [q,q].
2. If line 4 is executed, then vs left subtree contains an intervalthat overlaps [q,q] or no interval in vs right subtree overlaps[q,q].
13
7/29/2019 Augmented Data Structure
14/17
Theorem: Let I be a set ofn intervals. There is a data structure for I
of size O(n), such that the operations I NSERT, DELETE, and OVER-LAP each take time O(log n).
Theorem: Checking whether n axis-parallel rectangles in the plane
are pairwise disjoint can be done in O(n log n) time.
14
7/29/2019 Augmented Data Structure
15/17
Secondary Data Structures
Let v be a node in a search-tree with leaf-oriented storage. The
canonical subsetof v is the set of items stored in the subtree rooted
at v.
In a number of data structures the canonical subsets of the nodes are
stored in a secondary data structures associated with a node.
15
7/29/2019 Augmented Data Structure
16/17
16
7/29/2019 Augmented Data Structure
17/17
A secondary data structure might be an augmented data structure as
well:
17