Download presentation
Presentation is loading. Please wait.
1
Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg
2
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann2 Overview The measure problem 1D analysis 2D analysis Naïve solution Implicit area computation by segment tree Improved solution
3
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann3 The Measure Problem Victor Klee, 1977 Given a set of n horizontal line-segments, compute the length of their union on the real line.
4
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann4 1D Problem (Original) Sorting and partitioning –Total partitions (space): –Time: Sweep direction: Left to right –Event Q: –Status-measure T:
5
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann5 1D Problem (Original) Time complexities –Time per event: –Total sweep time: –Total runtime:
6
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann6 The Measure Problem in 2D Jon Bentley, 1977 Given a set of n rectangles on the 2D plane, compute the area of their union.
7
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann7 (x hi, y hi ) Representing a Rectangle (x lo, y lo ) r x lo x hi y lo y hi Assume that all rectangles in the set are non-trivial Sufficient to store bottom-left and top-right coordinates
8
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann8 2D Problem – Sweepline Approach ep i ep i+1 Sweep direction
9
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann9 2D Problem – Sweepline Approach Sorting and partitioning –Total partitions (space): –Time: Sweep direction: Left to right –Event Q: –Status-structure T: ep i
10
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann10 2D Sweepline – Naïve Solution Let m(i) be the 1D measure of the active vertical segments at ep i. Then the measure for the 2D slab between ep i and ep i+1 : In general, for k 2D slabs, the measure for the entire set of rectangles: ep i ep i+1
11
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann11 Analyses – 2D Naïve Maintaining the status-structure T, per event point ep i –Time (per insertion): –Time (per deletion): –Time to compute m(i): Total insertions (into T) = Total deletions (from T) = Overall performance of the naïve algorithm –Time complexity:
12
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann12 Analyses – Naïve Worst Case Worst case runtime: Can this be avoided?
13
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann13 Improving the Naïve Approach Main reason for inefficiency: Overcoming the inefficiency: –Limit the amount of work done at ep i by
14
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann14 Observation for Improvement Consider the slab between ep i and ep i+1 when a new rectangle q becomes active. q ep i ep i+1 q ep i ep i+1 q ep i ep i+1 q ep i ep i+1
15
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann15 Decomposing the Vertical Sweep Idea: All segments appearing on the vertical sweepline can be composed of a collection of consecutive fragments [v j, v j+1 ]. A single offline structure is sufficient to represent the vertical sweeps to collectively compute the measure m(i) at each ep i. Insertions and deletions of segments affect the structure only by changing the augmented values in the internal nodes. At the start of the event point ep i, the measure for the previous segment m(i-1) can be read off the root immediately.
16
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann16 The Segment Tree as Status-Structure The ordered (vertical) segments are entered as leaves in a balanced binary search tree . Each v j (except v 1 and v m ) will occur twice, representing the closed non-overlapping segment [v j, v j+1 ]. 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E v1v1 vmvm 1 3 3 5 5 6 6 8 8 9
17
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann17 Keeping Track of Segments The segment tree represents all O(n) partitions on the vertical axis. When a rectangle becomes active (or inactive), we mark the internal nodes in accordingly; i.e. we should be able to know –if the subtree under a node x in fully or partially covers a set of intervals – and thus, the measure at node x, and –the number of segments that fully covers the range of x. vi vj vk vi vj vk x x x’
18
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann18 Implicit Handling It is NOT necessary to mark all the individual fragments from which a segment q is composed. Why?
19
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann19 Classifying Nodes based on a Segment q Given a segment q = [v i, v j ], then a node in is said to be – q-full if it covers a segment fully contained in q – q-partial if it is not q-full but has a child that is either q-partial or q-full Consider the search paths for ‘[v i ’ and ‘v j ]’; let the node where the two paths diverge be t. –All nodes encountered before t must have been v1v1 vmvm [vi[vi vj]vj] t q
20
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann20 1-Umbrella of the Segment q The 1-umbrella of a segment q is the subtree of rooted at t consisting of –all the q-partial nodes on the hi-line from t to hi-tip, –all the q-partial nodes on the lo-line from t to lo-tip, and –all the q-full nodes which are directly connected to the hi-line or lo-line. [vi[vi vj]vj] t q hi-tip lo-tip hi-line lo-line
21
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann21 1-Umbrella of the Segment q Lemma: The 1-umbrella of the segment q can be built in O(log n) steps.
22
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann22 Marking Nodes on the 1-Umbrella We maintain the following information in for any sets of segments, where augment in the node x –x.val : The measure of the fragments in the subtree of x which are covered by 1-umbrellas through it or below it –x.cnt : A count of the number of times in which x becomes a q-full node of some umbrella. vi vj vk vm t
23
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann23 Inserting a Segment q into Input: –The root of the segment tree –The range q = [v i, v j ] Output: –The measure of the vertical line-segments at root.val Idea: –Percolating measure differences between successive levels in Determine the 1-umbrella for q. Handle measure differences from lo-tip to t. Handle measure differences from hi-tip to t. Combine measure differences and percolate to root.
24
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann24 Example – Activate qA 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] [5,6] v = 0 c = 0 [3,5] v = 0 c = 0 [1,3] [1,5] v = 0 c = 0 [6,9] [5,9] v = 0 c = 0 [1,9] v = 0 c = 0 Sweep direction qAqA
25
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann25 Example – Activate qB 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qBqB 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 0 c = 0 [5,6] v = 1 c = 1 [3,5] v = 2 c = 1 [1,3] [1,5] v = 2 c = 0 [6,9] v = 0 c = 0 [5,9] v = 1 c = 0 [1,9] v = 3 c = 0
26
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann26 Example – Activate qC 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qCqC 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 2 c = 1 [5,6] v = 1 c = 2 [3,5] v = 2 c = 1 [1,3] [1,5] v = 2 c = 0 [6,9] v = 2 c = 0 [5,9] v = 3 c = 0 [1,9] v = 5 c = 0
27
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann27 Special Cases When t equals lo-tip, then t also equals hi-tip. Why? The percolated measure difference have to be ‘killed’ if x.parent.cnt ≥ 1. Why?
28
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann28 Inserting a Segment Lemma: Inserting a segment and maintaining the information in requires O(log n) time.
29
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann29 Deleting a Segment Lemma: Deleting a segment and maintaining the information in requires O(log n) time.
30
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann30 Example – Deactivate qA 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qAqA 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 2 c = 1 [5,6] v = 1 c = 2 [3,5] v = 2 c = 1 [1,3] [1,5] v = 2 c = 0 [6,9] v = 2 c = 0 [5,9] v = 3 c = 0 [1,9] v = 8 c = 1
31
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann31 Example – Deactivate qC 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qCqC 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 2 c = 1 [5,6] v = 1 c = 1 [3,5] v = 0 c = 0 [1,3] [1,5] v = 0 c = 0 [6,9] v = 2 c = 0 [5,9] v = 3 c = 0 [1,9] v = 8 c = 1
32
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann32 Example – Activate qD, qE 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qDqD qEqE 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 2 c = 1 [5,6] v = 1 c = 1 [3,5] v = 0 c = 0 [1,3] v = 0 c = 0 [1,5] v = 0 c = 0 [6,9] v = 2 c = 0 [5,9] v = 3 c = 0 [1,9] v = 3 c = 0
33
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann33 Example – Deactivate qD 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qDqD 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 2 c = 2 [5,6] v = 1 c = 1 [3,5] v = 0 c = 0 [1,3] v = 2 c = 1 [1,5] v = 2 c = 0 [6,9] v = 2 c = 0 [5,9] v = 3 c = 0 [1,9] v = 5 c = 0
34
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann34 Example – Deactivate qE, qB 0 1 2 3 4 5 6 7 8 9 12345678910 0 A B C D E Sweep direction qEqE 1 3 3 5 5 6 6 8 8 9 [8,9] [6,8] v = 2 c = 2 [5,6] v = 1 c = 1 [3,5] v = 0 c = 0 [1,3] v = 2 c = 0 [1,5] v = 0 c = 0 [6,9] v = 2 c = 0 [5,9] v = 3 c = 0 [1,9] v = 3 c = 0
35
Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann35 The Improved Solution Theorem: The measure problem for a set of n rectangles in the plane can be solved on O(n log n) time.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.