0% found this document useful (0 votes)
5 views10 pages

Sweepline 1

The document discusses the Plane Sweep algorithm for finding the closest pair of points in a 2D space, detailing the algorithm's design technique and its efficiency. It outlines the process of maintaining a cleanliness property while updating the sweep line status and managing events. The total runtime for the algorithm is O(n log n), with specific operations such as presorting and using a balanced binary search tree for efficient point management.

Uploaded by

Anant Nimkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Sweepline 1

The document discusses the Plane Sweep algorithm for finding the closest pair of points in a 2D space, detailing the algorithm's design technique and its efficiency. It outlines the process of maintaining a cleanliness property while updating the sweep line status and managing events. The total runtime for the algorithm is O(n log n), with specific operations such as presorting and using a balanced binary search tree for efficient point management.

Uploaded by

Anant Nimkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CMPS 3130/6130 Computational Geometry

Spring 2015

Plane Sweep Algorithms I


Carola Wenk

1/20/15 CMPS 3130/6130 Computational Geometry 1


Closest Pair

• Problem: Given PR2, |P|=n, find the distance


between the closest pair in P

1/20/15 CMPS 3130/6130 Computational Geometry 2


Plane Sweep: An Algorithm
Design Technique
• Simulate sweeping a vertical line from left to right across the plane.
• Maintain cleanliness property: At any point in time, to the left of sweep
line everything is clean, i.e., properly processed.
• Sweep line status: Store information along sweep line
• Events: Discrete points in time when sweep line status needs to be
updated

1/20/15 CMPS 3130/6130 Computational Geometry 3


Plane Sweep: An Algorithm
Design Technique
• Simulate sweeping a vertical line from left to right across the plane.
• Maintain cleanliness property: At any point in time, to the left of sweep
line everything is clean, i.e., properly processed.
• Sweep line status: Store information along sweep line
• Events: Discrete points in time when sweep line status needs to be
updated
Algorithm Generic_Plane_Sweep:
Initialize sweep line status S at time x=-
Store initial events in event queue Q, a priority queue ordered by x-coordinate
while Q ≠ 
// extract next event e:
e = Q.extractMin();
// handle event:
Update sweep line status
Discover new upcoming events and insert them into Q

1/20/15 CMPS 3130/6130 Computational Geometry 4


Plane sweep for
Closest Pair
• Problem: Given PR2, |P|=n, find the distance of
the closest pair in P
• Sweep line status: Cleanliness property

– Store current distance Δ of closest pair of points to the


left of sweep line
– Store points in Δ-strip left of sweep line
– Store pointer to leftmost point in strip
• Events: All points in P. No new events will be
added during the sweep.
→ Presort P by x-coordinate.

1/20/15 CMPS 3130/6130 Computational Geometry 5


Plane sweep for
Closest Pair, II
O(n log n) • Presort P by x-coordinate
• How to store points in Δ-strip?
– Store points in Δ-strip left of sweep line in a balanced binary search tree,
ordered by y-coordinate
→ Add point, delete point, and search in O(log n) time
• Event handling:
– New event: Sweep line advances to point pP
– Update sweep line status:
O(n log n) total 1 • Delete points outside Δ-strip from search tree by using previous leftmost point in
strip and x-order on P
• Compute candidate points that may have distance  Δ from p:
O(n log n + 6n) total
2 – Perform a search in the search tree to find points in Δ–strip whose y-
coordinates are at most Δ away from p.y.
→ Δ x 2Δ rectangle
– Because of the cleanliness property each pair of these points has distance ≥Δ.
→ A Δ x 2Δ rectangle can contain at most 6 such points.
O(6n) total 3 • Check distance of these points to p, and possibly update Δ Δ
– No new events necessary to discover

Total runtime: O(n log n) Δ

1/20/15 CMPS 3130/6130 Computational Geometry Δ 6


Balanced Binary Search Tree
-- a bit different

1 17 43

6 8 12 14 26 35 41 42 59 61

key[x] is the maximum key of any leaf in the left subtree of x.


1/20/15 CMPS 3130/6130 Computational Geometry 7
Balanced Binary Search Tree
-- a bit different x
17
x >x
8 42

1 14 35 43

1 6 12 17 26 41 43 59

6 8 12 14 26 35 41 42 59 61

key[x] is the maximum key of any leaf in the left subtree of x.


1/20/15 CMPS 3130/6130 Computational Geometry 8
Balanced Binary Search Tree
-- a bit different x
17
x >x
8 42

1 14 35 43

1 6 12 17 26 41 43 59

6 8 12 14 26 35 41 42 59 61

RANGE-QUERY([7, 41])
1/20/15 CMPS 3130/6130 Computational Geometry 9
Plane Sweep: An Algorithm
Design Technique
• Plane sweep algorithms (also called sweep
line algorithms) are a special kind of
incremental algorithms
• Their correctness follows inductively by
maintaining the cleanliness property
• Common runtimes in the plane are O(n log n):
– n events are processed
– Update of sweep line status takes O(log n)
– Update of event queue: O(log n) per event

1/20/15 CMPS 3130/6130 Computational Geometry 10

You might also like