Closest Pair of Points in the Plane. Closest pair of points. Closest Pair of Points. Closest Pair of Points

Similar documents
5.4 Closest Pair of Points

Randomized algorithms. Inge Li Gørtz

Closest Pair of Points. Cormen et.al 33.4

Divide and Conquer 1

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication

Ch5. Divide-and-Conquer

Algorithm Design and Analysis

Plan for Today. Finish recurrences. Inversion Counting. Closest Pair of Points

Divide-Conquer-Glue Algorithms

Chapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

5. DIVIDE AND CONQUER I

Divide-and-Conquer. Combine solutions to sub-problems into overall solution. Break up problem of size n into two equal parts of size!n.

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego

CSE 421 Algorithms: Divide and Conquer

CSE 202 Divide-and-conquer algorithms. Fan Chung Graham UC San Diego

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Divide and conquer algorithms. March 12, 2018 CSCI211 - Sprenkle. What is a recurrence rela&on? How can you compute D&C running &mes?

Lecture 4 CS781 February 3, 2011

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Divide-and-Conquer Algorithms

Geometric Computation: Introduction. Piotr Indyk

Parallel Models RAM. Parallel RAM aka PRAM. Variants of CRCW PRAM. Advanced Algorithms

Algorithms: Lecture 7. Chalmers University of Technology

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions

1 Closest Pair Problem

We can use a max-heap to sort data.

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8!

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Deterministic and Randomized Quicksort. Andreas Klappenecker

CSC Design and Analysis of Algorithms

CS 410/584, Algorithm Design & Analysis, Lecture Notes 8

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

Rank. Selection Problem

Selection Problem. Rank. Divide-And-Conquer Selection. Selection By Sorting

Computational Geometry

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Randomized Quickselect and Randomized Quicksort. Nishant Mehta September 14 th, 2017

Problem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n.

Computer Science Approach to problem solving

Divide and Conquer. Divide and Conquer

Geometric Primitives. primitive operations convex hull closest pair voronoi diagram. primitive operations convex hull closest pair voronoi diagram

Computational geometry

Divide and Conquer. Algorithm Fall Semester

CS210 Project 5 (Kd-Trees) Swami Iyer

Computational Geometry. Algorithm Design (10) Computational Geometry. Convex Hull. Areas in Computational Geometry

1. Meshes. D7013E Lecture 14

Divide-and-Conquer. Dr. Yingwu Zhu

Divide and Conquer 4-0

Union Find. Data Structures and Algorithms Andrei Bulatov

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

6. Concluding Remarks

Geometric Algorithms. Geometric search: overview. 1D Range Search. 1D Range Search Implementations

In what follows, we will focus on Voronoi diagrams in Euclidean space. Later, we will generalize to other distance spaces.

26 The closest pair problem

High Dimensional Indexing by Clustering

Review implementation of Stable Matching Survey of common running times. Turn in completed problem sets. Jan 18, 2019 Sprenkle - CSCI211

Programming II (CS300)

COT5405: GEOMETRIC ALGORITHMS

Computational Geometry 2D Convex Hulls

Lecture 7. Transform-and-Conquer

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer

1 Proximity via Graph Spanners

Introduction to. Algorithms. Lecture 2. Prof. Constantinos Daskalakis

Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

Advanced Algorithm Homework 4 Results and Solutions

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

Computer Graphics II

Outline. CS38 Introduction to Algorithms. Approximation Algorithms. Optimization Problems. Set Cover. Set cover 5/29/2014. coping with intractibility

11. APPROXIMATION ALGORITHMS

COS 226 Lecture 15: Geometric algorithms. Warning: intuition may mislead (continued)

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול

Module 2: Classical Algorithm Design Techniques

CSC Design and Analysis of Algorithms. Lecture 5. Decrease and Conquer Algorithm Design Technique. Decrease-and-Conquer

Voronoi diagram and Delaunay triangulation

A 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted.

Tree-Weighted Neighbors and Geometric k Smallest Spanning Trees

Union Find 11/2/2009. Union Find. Union Find via Linked Lists. Union Find via Linked Lists (cntd) Weighted-Union Heuristic. Weighted-Union Heuristic

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort)

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

11. APPROXIMATION ALGORITHMS

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

Algorithms. Algorithms 1.4 ANALYSIS OF ALGORITHMS

Algorithmic Paradigms

Geometric data structures:

CSCI 121: Searching & Sorting Data

Transform & Conquer. Presorting

15-451/651: Design & Analysis of Algorithms April 18, 2016 Lecture #25 Closest Pairs last changed: April 18, 2016

Principles of Algorithm Design

11. APPROXIMATION ALGORITHMS

Sorting. Divide-and-Conquer 1

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

CPS 616 TRANSFORM-AND-CONQUER 7-1

15-451/651: Design & Analysis of Algorithms November 20, 2018 Lecture #23: Closest Pairs last changed: November 13, 2018

Approximation Algorithms

100 points total. CSE 3353 Homework 2 Spring 2013

Merge Sort. Run time typically depends on: Insertion sort can be faster than merge sort. Fast, able to handle any data

Triangulation and Convex Hull. 8th November 2018

UNIT-2. Problem of size n. Sub-problem 1 size n/2. Sub-problem 2 size n/2. Solution to the original problem

Algorithms. Algorithms GEOMETRIC APPLICATIONS OF BSTS. 1d range search line segment intersection kd trees interval search trees rectangle intersection

Transcription:

Closest Pair of Points Closest pair of points. Given n points in the plane, find a pair with smallest euclidean distance between them. Closest Pair of Points in the Plane Inge i Gørtz The slides on the deterministic algorithm for finding the closest pair of points is a modification of slides made by Kevin. Closest Pair of Points Closest pair of points. Given n points in the plane, find a pair with smallest euclidean distance between them. Fundamental geometric primitive. Graphics, computer vision, geographic information systems, molecular modeling, air traffic control. Special case of nearest neighbor, Euclidean MST, Voronoi diagrams. Brute force. Compare all pairs => O(n ) time. -D version. Sort and scan => O(n log n) time. Closest pair of points A divide-and-conquer algorithm Simplifying assumption. No two points coincide (for a simpler presentation). The slides on the deterministic algorithm for finding the closest pair of points is a modification of the slides made by Kevin.

Closest pair: Divide-and-Conquer Divide: Conquer: Closest pair: Divide-and-Conquer Divide: draw vertical line so that roughly n/ points on each side. Conquer: Closest pair: Divide-and-Conquer Divide: draw vertical line so that roughly n/ points on each side. Conquer: find closest pair in each side recursively. Closest pair: Divide-and-Conquer Divide: draw vertical line so that roughly n/ points on each side. Conquer: find closest pair in each side recursively. Find closest pair with one point in each side. seems like Θ(n ) Return best of solutions

Find closest pair with point on each side Find closest pair with one point in each side, assuming that distance <. Find closest pair with point on each side Find closest pair with one point in each side, assuming that distance <. Observation: only need to consider points within of line. = min(, ) = min(, ) Find closest pair with point on each side Find closest pair with one point in each side, assuming that distance <. Observation: only need to consider points within of line. Sort points in -strip by their y coordinate. Find closest pair with point on each side Find closest pair with one point in each side, assuming that distance <. Observation: only need to consider points within of line. Sort points in -strip by their y coordinate. Only check distances between these points within positions in sorted list! = min(, ) = min(, )

Find closest pair with point on each side Closest Pair Algorithm Def. et s i be the point in the -strip, with the i th smallest y-coordinate. Closest-Pair(p,, p n ) { Claim. If i j, then the distance between s i and s j is at least. Pf. 9 j If n < compute closest pair by comparing all pairs. Compute separation line such that half the points are on one side and half on the other side. O(n log n) s j at most apart from s i then the difference in y-coordinate is at most. = Closest-Pair(left half) = Closest-Pair(right half) = min(, ) T(n / ) No two points lie in same ½-by-½ box: s r + = 0. < At most points within distance (one in each other box). i 9 0 ½ ½ } Delete all points further than from separation line Sort remaining points by y-coordinate. Scan points in y-order and compare distance between each point and next neighbors. If any of these distances is less than, update. return. O(n log n) Closest Pair Algorithm Closest Pair Algorithm Analysis: T(n) = T(n/) + O(n log n), for n >. T(n) = O(), for n. T(n) = O(n log n). Can improve this by pre-sorting points: Start by constructing sorted lists X and Y containing all points sorted after x- and y-coordinate, resp. Divide: Split X-array in middle. Use linear time to split Y-array into (according to x-coordinate). Prune Y-array (only consider points with x-coordinate within of ). Presort points into lists X and Y after x- and y-coordinate, respectively. Closest-Pair(X[ n],y[ n]) { If n < compute closest pair by comparing all pairs. Compute separation line such that half the points are on one side and half on the other side. = Closest-Pair(left half) = Closest-Pair(right half) = min(, ) Delete all points further than from separation line Sort remaining points by y-coordinate. Scan points in y-order and compare distance between each point and next neighbors. If any of these distances is less than, update. T(n / ) } return.

Closest Pair Algorithm Analysis: Total time: T(n) + O(n log n). T(n) = T(n/) +, n>. T(n) = O(), n. Thus T(n) = O(n log n). In total O(n log n). Closest pair of points A randomized algorithm Randomized algorithm Assume wlog that points are in the unit square. Sort points in random order. et = d(p,p). Check for each point pi (in order) if there exists a point pj, j<i, such that d(pi,pj) <. If such a point found. Update. How to check a point current smallest distance. Divide unit square into subsquares with side lengths /. / / 9 0 9 0

How to check a point current smallest distance. Divide unit square into subsquares with side lengths /. If two points i and j are in the same subsquare then d(i,j) <. How to check a point current smallest distance. Divide unit square into subsquares with side lengths /. If two points i and j are in the same subsquare then d(i,j) <. If d(i,j) < then j is in the x grid of subsquares around i. / / / / 9 0 9 0 Closest Pair of Points: Randomized algorithm Use hashtable to store which square a point is in. Only store points already looked at (red points). Closest Pair of Points Use hashtable to store which square a point is in. Only store points already looked at (red points). When starting new round: rehash all points from i. 9 0 9 0

Closest Pair of Points Use hashtable to store which square a point is in. Only store points already looked at (red points). When starting new round: rehash all points from i. Closest Pair of Points: Analysis Number of lookup operations: Number of distance calculations: Number of MakeDictionary operations: 9 0 Closest Pair of Points: Analysis Number of lookup operations: Number of distance calculations: Number of MakeDictionary operations: Number of insertions: Random variable X = number of insertions Random variable Pr[Xi = ] /i i= X i = ( i causes to change 0 otherwise Expected number of insertions: nx nx nx E[X] =n + i E[X i ]=n + i Pr[X i ] apple n + i /i = n +n =n. i= i= Use hashtable as dictionary: time in total.