1 Closest Points A famous algorithmic problem... Given a set of points in the plane (cities in the U.S., transistors on a circuit board, computers on a.

Slides:



Advertisements
Similar presentations
Two Segments Intersect?
Advertisements

Spatial Information Systems (SIS) COMP Terrain modeling and geometric problems (part 2)
Computational Geometry
Searching on Multi-Dimensional Data
Brute-Force Triangulation
2/3/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Triangulations and Guarding Art Galleries II Carola Wenk.
Computing Convex Hulls CLRS 33.3
MA/CSSE 473 Day 13 Divide and Conquer Closest Points Convex Hull Answer Quiz Question 1.
Rank Rank of an element is its position in ascending key order. [2,6,7,8,10,15,18,20,25,30,35,40] rank(2) = 0 rank(15) = 5 rank(20) = 7.
9/12/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries II Carola Wenk.
Advanced Algorithm Design and Analysis (Lecture 10) SW5 fall 2004 Simonas Šaltenis E1-215b
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem.
9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk.
Intersections. Intersection Problem 3 Intersection Detection: Given two geometric objects, do they intersect? Intersection detection (test) is frequently.
November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
Computational Geometry -- Voronoi Diagram
Efficient Algorithmic Techniques for Several Multidimensional Geometric Data Management and Analysis Problems Mugurel Ionut Andreica Politehnica University.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
10/2/20061 Algorithms on grids Natasha Gelfand Geometry Seminar Fall 2006.
Special Cases of the Hidden Line Elimination Problem Computational Geometry, WS 2007/08 Lecture 16 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen,
Lecture 33 CSE 331 Nov 20, Homeworks Submit HW 9 by 1:10PM HW 8 solutions at the end of the lecture.
1 Geometric Solutions for the IP-Lookup and Packet Classification Problem (Lecture 12: The IP-LookUp & Packet Classification Problem, Part II) Advanced.
Geometric Data Structures Computational Geometry, WS 2007/08 Lecture 13 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Hidden-Line Elimination Computational Geometry, WS 2006/07 Lecture 14 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Closest Pair of Points Computational Geometry, WS 2006/07 Lecture 9, Part II Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen,
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
COMP s1 Computing 2 Complexity
Orthogonal Line Segment Intersection Given N horizontal and N vertical line segments, find all intersections. All x and y coordinates are distinct.
Orthogonal Range Searching I Range Trees. Range Searching S = set of geometric objects Q = query object Report/Count objects in S that intersect Q Query.
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
UNC Chapel Hill M. C. Lin Line Segment Intersection Chapter 2 of the Textbook Driving Applications –Map overlap problems –3D Polyhedral Morphing.
External Memory Algorithms for Geometric Problems Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)
Computational Geometry (35/33) Line Segments and cross-product Segment intersection and Sweep Line Convex Hull and Graham’s Scan, Jarvis’s march Divide-and-Conquer.
Intro to Computer Algorithms Lecture 11 Phillip G. Bradford Computer Science University of Alabama.
B-trees and kd-trees Piotr Indyk (slides partially by Lars Arge from Duke U)
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
Theory of Algorithms: Brute Force. Outline Examples Brute-Force String Matching Closest-Pair Convex-Hull Exhaustive Search brute-force strengths and weaknesses.
Mehdi Mohammadi March Western Michigan University Department of Computer Science CS Advanced Data Structure.
1 Closest Pair of Points (from “Algorithm Design” by J.Kleinberg and E.Tardos) Closest pair. Given n points in the plane, find a pair with smallest Euclidean.
1 Prune-and-Search Method 2012/10/30. A simple example: Binary search sorted sequence : (search 9) step 1  step 2  step 3  Binary search.
1 Searching the dictionary ADT binary search binary search trees.
Divide and Conquer Applications Sanghyun Park Fall 2002 CSE, POSTECH.
CMPS 3130/6130 Computational Geometry Spring 2015
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
7.3 Divide-and-Conquer Algorithms and Recurrence Relations If f(n) represents the number of operations required to solve the problem of size n, it follow.
UNC Chapel Hill M. C. Lin Computing Voronoi Diagram For each site p i, compute the common inter- section of the half-planes h(p i, p j ) for i  j, using.
Lecture 7 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms.
Problem Definition I/O-efficient Rectangular Segment Search Gautam K. Das and Bradford G. Nickerson Faculty of Computer science, University of New Brunswick,
9/8/10CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2010 Triangulations and Guarding Art Galleries Carola Wenk.
Center for Graphics and Geometric Computing, Technion 1 Computational Geometry Chapter 9 Line Arrangements.
1/20/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Plane Sweep Algorithms I Carola Wenk.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
UNC Chapel Hill M. C. Lin Geometric Data Structures Reading: Chapter 10 of the Textbook Driving Applications –Windowing Queries Related Application –Query.
Line Sweep Algorithms Schalk-Willem Krüger – 2009 Training Camp 1 presentation.start();
Advanced Algorithms Analysis and Design
CMPS 3130/6130 Computational Geometry Spring 2017
Algorithm design techniques Dr. M. Gavrilova
CMPS 3130/6130 Computational Geometry Spring 2017
Rank Rank of an element is its position in ascending key order.
Computational Geometry (35/33)
Algorithms and Data Structures Lecture XIV
Given a list of n  8 integers, what is the runtime bound on the optimal algorithm that sorts the first eight? O(1) O(log n) O(n) O(n log n) O(n2)
Presentation transcript:

1 Closest Points A famous algorithmic problem... Given a set of points in the plane (cities in the U.S., transistors on a circuit board, computers on a network, etc.) find which pair of points is the closest together. Today we will study algorithms and data structures for solving this problem.

2 Closest Pair formal definition Algorithms for determining the closest pair: -brute force O(N 2 ) -divide-and-conquer O(N log N) -plane-sweep O(N log N)

3 Brute Force Algorithm (x1, y1) (x2, y2) p1 p2 d(p1, p2) =(x2 - x1) 2 + (y2 - y1) 2 Time Complexity: O( N 2 )

4 Plane-Sweep Algorithm Maybe we can avoid checking the distance between every pair... Plane-sweep worked for segment intersection... Key observation: if the closest pair of points to the left of the sweep line is distance d apart, the next point encountered can’t be a closest pair with any point more than d units to the left of the line The closest point to the left of p can only be in the red-shaded region

5 Stored Information Maintain the following information: –closest pair (a,b) found so far, and distance d between them. –ordered dictionary S of the points lying in a strip of width d to the left of the sweep line, using the y-coordinates as keys

6 Updating When the sweep line encounters a point p: –update dictionary so it only contains points that might be a closest pair with p –remove all points r such that x(p)-x(r)>d from S –find the closest point q to p in S –if d(p,q) < d then update the current closest pair and distance –insert p into S

7 Searching the Dictionary How to quickly find the closest point in the dictionary? (Note: there could be O(N) points in the dictionary.) Have x, y spacing so that y = d/(n-1) Good news: not all of the points in the dictionary can improve d. The only eligible points are in the half circle of radius d centered at p. d p

8 Searching the Dictionary II But how to search in a half-circle? –a rectangle is almost a half-circle… –do a range search in the interval [y(p)-d,y(p)+d] –this will get all the points in the half-circle (and maybe some others) Use brute-force to check the distance to each point returned by the range query But isn’t that still a potentially large number of points? –actually, there are at most 6 –key observation: all of the points in the dictionary are at least distance d from each other d p 2d

9 Putting It All Together sort points by x-coordinate and store in ordered sequence X maintain references to two positions in sequence -firstInStrip: the leftmost point in S -lastInStrip: the new point to be added to S at each step.. lastInStrip  X.after(lastInStrip) // advance lastInStrip // remove points that are no longer candidates from dictionary while x(point(firstInStrip)) < x(point(lastInStrip))-d do S.remove(point(firstInStrip)) firstInStrip  X.after(firstInStrip) // update closest point information find point q closest to point(lastInStrip) in S if d(p,q) < d then update closest pair d  d(p,q) S.insert(point(lastInStrip)) // insert new point into dictionary

10 An Example

11 An Example Continued

12 Still Going...

13 Example Completed

14 Running Time initial sort takes O(N log N) time each point is inserted and removed once from S –S has at most N elements, so each insertion/removal takes O(log N) time –total insertion/removal time is O(N log N) dictionary is searched once each time a point is inserted into S –each range query takes O(log N + 6) = O(log N) time –total time for range queries is O(N log N) distance computations performed each time a point is inserted into S –at most 6 computations at each time –total time for distance computations is O(N)