510 likes | 708 Views
Segment Tree and Its Usage for geometric Computations. Shmuel Wimer Bar Ilan Univ., Eng. Faculty Technion, EE Faculty. Motivation. We may be interested in calculating the underling area, perimeter or contour construction. Segment Tree Definition. Introduced by J. L. Bentley in 1977
E N D
Segment Tree and Its Usage for geometric Computations Shmuel Wimer Bar Ilan Univ., Eng. Faculty Technion, EE Faculty Segment Tree
Motivation We may be interested in calculating the underling area, perimeter or contour construction Segment Tree
Segment Tree Definition • Introduced by J. L. Bentley in 1977 • Data structure designed to handle intervals on the real line • Intervals end points belong to a fixed set of abscissas • Abscissas can be normalized to range [1,N] without loss of generality by using a lookup table • Given an interval [l,r], the segment tree T(l,r) is a rooted binary tree defined recursively Segment Tree
4,15 4,9 9,15 4,6 6,9 9,12 12,15 4,5 5,6 6,7 7,9 9,10 10,12 12,13 13,15 7,8 8,9 10,11 11,12 13,14 14,15 Segment Tree
Insertion and Deletion Segment Tree
Insertion and Deletion Segment Tree
73,77 1,257 65,97 81,97 73,81 1,129 74,75 75,77 77,81 73,75 65,129 97,129 65,81 97,115 97,105 105,115 105,109 105,107 Segment Tree
Allocation and De-Allocation • Depends on application. • If we wish to know the cardinality of cover of [B[v],E[v]] then a counter C[v] is associated with node v: • C[v] = C[V]+1 is allocation for INSERT • C[v] = C[V]-1 is de-allocation for DELETE • In many cases C[v] indicates the presence of material, so we’ll be interested in whether C[v] > 0 (material exists) or C[v]==0 (no material). Segment Tree
1D Measure of Union of Intervals Segment Tree
1D Measure of Union of Intervals Segment Tree
2D Measure (Area) of Union of Rectangles Segment Tree
2D Measure (Area) of Union of Rectangles Segment Tree
scan-line Segment Tree
Efficient Calculation of m(xi) Segment Tree
Perimeter of Union of Rectangles Perimeter is the length sum of: vertical edges horizontal edges Segment Tree
The Contour of Union of Rectangles Segment Tree
Completing the Cycles of Contour Segment Tree
e3 e6 e8 e1 e10 e5 e7 e2 e9 e4 Segment Tree
There’s no ambiguity in deciding whether to go to left or right triplet when an horizontal edge is decided. It follows that a pair of successive triplets defines horizontal edges. Consequently, once two successive triplets are traversed and define a new horizontal edge, the number of triplets on both the left and the right parts of the list must be even. Therefore, if the index of a triplet is even, its left adjacent triplet is paired, otherwise, the right triplet is paired. Segment Tree
Run-time Complexity Segment Tree
U’ U” U’ U” |P(U’)+ P(U”)|=7 |P(U’)+ P(U”)|=5 Segment Tree