Download presentation
Presentation is loading. Please wait.
1
Closest Pair of Points Computational Geometry, WS 2006/07 Lecture 9, Part II 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 2006/07 Prof. Dr. Thomas Ottmann2 Overview Motivation Closest Pair algorithms –Improving the naïve runtime –Divide and Conquer –Scan Line Analyses
3
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann3 Geometry and Air Traffic Control » Avoid collisions at all costs. » Start by finding the two aeroplanes closest to each other, at specific elevations. » During peak times over 5000 planes, per hour, around Frankfurt airspace.
4
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann4 Geometry and Astronomy » Find the two nearest objects in space.
5
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann5 Search Quickly… and Why? » Find the two nearest objects in space.
6
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann6 Problem Description Input: A set S of n points in the plane. Output: The pair of points with the shortest Euclidean distance between them. Other applications in fundamental geometric primitive: –Graphics, computer vision, geographic information systems, molecular modeling –Special case of nearest neighbour, Euclidean MST, Voronoi
7
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann7 Closest Pair of Points Naïve method: Brute force. –Check all pair of points p and q with Θ(n 2 ) comparisons. 1D version –Simple if all points are on a single line. –Run time O(n log n) Key to reducing quadratic runtime of the naïve method: Simply don´t visit each point n times.
8
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann8 Algorithm: DAC – Divide Sort S in ascending order of x-coordinates. Find the median line L, so that we have ½ n points in S L and ½ n points S R. SLSL SRSR
9
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann9 Algorithm: DAC – Conquer Recursively, find the closest pair in S L and S R. SLSL SRSR
10
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann10 Algorithm: DAC – Merge (Strip-Margins) Assuming that distance < S = min( SL, SR ). Observation: Only need to consider the points within S of line L. SLSL SRSR SS S = min(12,21)
11
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann11 Handling Merge Sort points in 2 S -strip in ascending y-coordinate order. (First observation) Only check those points within 11 positions in sorted list. SLSL SRSR SS S = min(12,21)
12
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann12 Comparing Efficiently Definition: Let s i be the point in the 2 S -strip with the i th smallest coordinate. Claim: If |i - j| 12, then the distance between s i and s j is at least S. Proof: The points s i and s j cannot lie in same ½ S -by- ½ S box. s i and s j are at least 2 rows apart, and have distance 2(½ S ). Fact: The above still holds if we replace 12 with 7. SS SS
13
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann13 Closest Pair: DAC Algorithm Algorithm: Closest-Pair( S = {p 1, …, p n } ) Sort all n points in ascending x-coordinate order Compute the median line L, and divide S into S L and S R Set SL Closest-Pair(S L ) Set SR Closest-Pair(S R ) Set S min( SL, SR ) Delete all points further than S from separation line L Sort remaining points in ascending y-coordinate order Scan points in y-order and compare distance between each point and next 7 neighbours. Update S if new shorter distance is found. Return S
14
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann14 Closest Pair: DAC Analysis Run time: T(N) 2T(N/2) + O(N log N) T(N) = O(N log 2 N) Can we achieve a better run time? Yes. Don’t sort points in strip from scratch each time. Each recursive step returns two lists: all points sorted by y- coordinate, and all points sorted by x-coordinate. Sort by merging two pre-sorted list. T(N) 2T(N/2) + O(N) T(N) = O(N log N) Space: O(n)
15
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann15 Algorithm: Scan-Line Sort S in ascending order of x-coordinates. Place sorted points p 1, …, p n in the event-queue. Initialise distance(p 1, p 2 ). Start scanning from p 3. » Event-points? » Status structure?
16
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann16 The Status-Structure Maintain the status-structure ( -slab): –Insert the new event-point p i. –Remove all points that are greater than distance to the left of the current event-point p i. –All points in the status structure are maintained in ascending y- coordinate order.
17
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann17 The Status-Structure Maintain the status-structure ( -slab): –Insert the new event-point p i. –Remove all points that are greater than distance to the left of the current event-point p i. –All points in the status structure are maintained in ascending y- coordinate order. –Perform the ‘Efficient Comparison’, as described earlier, BUT only between the new event point p i and at most 7 other nearest points to p i. –Update if a shorter distance is found.
18
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann18 Closest Pair: Scan-Line Analysis Invariant: Whenever an event-point p i has been handled, then is the minimum distance between any pair of points encountered from p 1 up to p i. Run time: O(n log n) Space: O(n)
19
Computational Geometry, WS 2006/07 Prof. Dr. Thomas Ottmann19 Related Problems Nearest neighbour query: –Given a set S of n points, and a query point q, determine which s S is closest to q. –Brute force: O(n) –Goal: O(n log n) pre-processing, O(log n) per query. Voronoi region, VR(S): –A set of points closest to a given point. Voronoi diagram, VD(S): –Planar subdivision deliniating Voronoi regions. Delaunay Triangulation (the dual of VD(S)).
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.