Closest Pair Given a set S = {p1, p2,..., pn} of n points in the plane find the two points of S whose distance is the smallest. Images in this presentation.

Slides:



Advertisements
Similar presentations
Comments We consider in this topic a large class of related problems that deal with proximity of points in the plane. We will: 1.Define some proximity.
Advertisements

Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
A simple example finding the maximum of a set S of n numbers.
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.
Prune-and-Search Method
Lecture 4 Divide and Conquer for Nearest Neighbor Problem
The Divide-and-Conquer Strategy
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. Problem Reduction Dr. M. Sakalli Marmara Unv, Levitin ’ s notes.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Lectures on Recursive Algorithms1 COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski.
Convex Hulls in Two Dimensions Definitions Basic algorithms Gift Wrapping (algorithm of Jarvis ) Graham scan Divide and conquer Convex Hull for line intersections.
Reminder: Closest-Pair Problem Given a collection P of n points in  × , obtain the two points p1 and p2 such that their distance is less or equal that.
The Divide-and-Conquer Strategy
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
By Groysman Maxim. Let S be a set of sites in the plane. Each point in the plane is influenced by each point of S. We would like to decompose the plane.
Introduction to Algorithms
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
CSL758 Instructors: Naveen Garg Kavitha Telikepalli Scribe: Manish Singh Vaibhav Rastogi February 7 & 11, 2008.
Updated QuickSort Problem From a given set of n integers, find the missing integer from 0 to n using O(n) queries of type: “what is bit[j]
CS38 Introduction to Algorithms Lecture 7 April 22, 2014.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
Prune-and-search Strategy
5 - 1 § 5 The Divide-and-Conquer Strategy e.g. find the maximum of a set S of n numbers.
Closest Pair of Points Computational Geometry, WS 2006/07 Lecture 9, Part II Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen,
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
A = p 4 B = p 5 CP = E[ p 7, p 2, p 3, p 6, p 1, p 8 ] S[p 4, p 5 ] d min = d 45 Plane Sweep Algorithm for Closest Pair Problem E=Event QueueS=Status Queue.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
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.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
5 -1 Chapter 5 The Divide-and-Conquer Strategy A simple example finding the maximum of a set S of n numbers.
© The McGraw-Hill Companies, Inc., Chapter 6 Prune-and-Search Strategy.
File Organization and Processing Week 13 Divide and Conquer.
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.
Divide and Conquer Applications Sanghyun Park Fall 2002 CSE, POSTECH.
Divide-and-Conquer. Outline Introduction Merge Sort Quick Sort Closest pair of points Large integer multiplication.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Digital Topology CIS 601 Fall 2004 Longin Jan Latecki.
Common Intersection of Half-Planes in R 2 2 PROBLEM (Common Intersection of half- planes in R 2 ) Given n half-planes H 1, H 2,..., H n in R 2 compute.
Copyright © Cengage Learning. All rights reserved. 15 Multiple Integrals.
Advanced Algorithms Analysis and Design
Rank Rank of an element is its position in ascending key order.
Chapter 4 Divide-and-Conquer
Chapter 5 Divide & conquer
Minimum Spanning Tree 8/7/2018 4:26 AM
CSCE350 Algorithms and Data Structure
Algorithm design techniques Dr. M. Gavrilova
Orthogonal Range Searching and Kd-Trees
Rank Rank of an element is its position in ascending key order.
Computational Geometry (35/33)
Divide and Conquer / Closest Pair of Points Yin Tat Lee
Chapter 5 Divide and Conquer
Punya Biswas Lecture 15 Closest Pair, Multiplication
Lecture 30 CSE 331 Nov 11, 2016.
Master Theorem Yin Tat Lee
Richard Anderson Lecture 13 Divide and Conquer
Divide and Conquer / Closest Pair of Points Yin Tat Lee
Lecture 30 CSE 331 Nov 10, 2017.
Divide-and-Conquer The most-well known algorithm design strategy:
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Topic: Divide and Conquer
Lecture 15, Winter 2019 Closest Pair, Multiplication
Lecture 15 Closest Pair, Multiplication
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)
Algorithm Course Algorithms Lecture 3 Sorting Algorithm-1
Presentation transcript:

Closest Pair Given a set S = {p1, p2,..., pn} of n points in the plane find the two points of S whose distance is the smallest. Images in this presentation were taken from: Lec15

Closest Pair – Naïve Algorithm Pseudo code for each pt i  S for each pt j  S and i<>j { compute distance of i, j if distance of i, j < min_dist min_dist = distance i, j } return min_dist Time Complexity– O(n 2 ) Can we do better?

Closest Pair – Divide & Conquer Divide the problem into two equal-sized sub problems Solve those sub problems recursively Merge the sub problem solutions into an overall solution

Closest Pair – Divide & Conquer Assume that we have solutions for sub problems S1, S2. How can we merge in a time-efficient way? The closest pair can consist of one point from S 1 and another from S 2 Testing all posibilities requires: O(n/2) · O(n/2)  O(n 2 ) Not good enough

Closest Pair – Divide & Conquer dimension d = 2 Partition two dimensional set S into subsets S 1 and S 2 by a vertical line l at the median x coordinate of S. Solve the problem recursively on S 1 and S 2. Let {p1, p2} be the closest pair in S 1 and {q1, q2} in S 2. Let  1 = distance(p1,p2) and  2 = distance(q1,q2) Let  = min(  1,  2 ) S1S1 l S2S2 22 11 p1p1 p2p2 q2q2 q1q1

Closest Pair – Divide & Conquer dimension d = 2 In order to merge we have to determine if exists a pair of points {p, q} where p  S 1, q  S 2 and distance(p, q) < . If so, p and q must both be within  of l. Let P 1 and P 2 be vertical regions of the plane of width  on either side of l. If {p, q} exists, p must be within P 1 and q within P 2. However, every point in S 1 and S 2 may be a candidate, as long as each is within  of l, which implies: O(n/2)  O(n/2) = O(n 2 ) Can we do better ? P1P1 lP2P2 22 q2q2 q1q1 S1S1 S2S2  11 p1p1 p2p2

Closest Pair – Divide & Conquer dimension d = 2 For a point p in P 1, which portion of P 2 should be checked? We only need to check the points that are within  of p. Thus we can limit the portion of P2. The points to consider for a point p must lie within   2  rectangle R. At most, how many points are there in rectangle R? P1P1 l p S1S1  P2P2 S2S2 

Closest Pair – Divide & Conquer dimension d = 2 How many points are there in rectangle R? Since no two points can be closer than , there can only be at most 6 points Therefore, 6  O(n/2)  O(n) Thus, the time complexity is O(n log n) P1P1 lP2P2 p  S1S1 S2S2   R How do we know which 6 points to check?

Closest Pair – Divide & Conquer dimension d = 2 How do we know which 6 points to check? Project p and all the points of S 2 within P 2 onto l. Only the points within  of p in the y projection need to be considered (max of 6 points). After sorting the points on y coordinate we can find the points by scanning the sorted lists. Points are sorted by y coordinates. To prevent resorting in O(n log n) in each merge, two previously sorted lists are merged in O(n). Time Complexity: O(n log n)