






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Rectangles or more general polygons in 2 -space.
8 11
6
7
Source address
[3,11] is stored in node p iff all leaves in subtree rooted at p are highlighted and no ancestor of p
Each node of a segment tree contains 0 or more
Need to store only those nodes that contain intervals
Each interval is in O(log n) nodes.
- 1, - 1,7 7, - 1,4 4,7 7,10 10, insert(s, e, v) {// insert [s,e] into subtree rooted at v if (s <= s(v) && e(v) <= e) add [s,e] to v; // interval spans node range else { if (s < (s(v) + e(v))/2) insert(s,e,v.leftChild); if (e > (s(v) + e(v))/2) insert(s,e,v.rightChild); } }
1, 1,7 (^) 7,
1,4 4,7 7,10 10,
1,2 2,
2,3 3,
4,5 5,
5,6 6,
8,9 9,10 11,12 12,
Let L and R, respectively, be the leaves for [s,s+1] and [e – 1,e].
1,2 2,
2,3 3,
4,5 5,
5,6 6,
7,8 8,10 10,11 11,
3,4 8,9 9,10 11,12 12,
10,
delete(s, e, v) {// delete [s,e] from subtree rooted at v if (s <= s(v) && e(v) <= e) delete [s,e] from v; // interval spans node range else { if (s < (s(v) + e(v))/2) delete(s,e,v.leftChild); if (e > (s(v) + e(v))/2) delete(s,e,v.rightChild); } }
1,
1,4 4,7 7,10 10,
1,2 2,
2,3 3,
4,5 5,
5,6 6,
7,8 8,10 10,11 11,
8,9 9,10 11,12 12,
W
5,
W
W
W W
O(log n + s), where s is the # of segments in the answer.