5.4 Closest Pair of Points



Similar documents
Closest Pair of Points. Kleinberg and Tardos Section 5.4

CSE 421 Algorithms: Divide and Conquer

Closest Pair Problem

28 Closest-Point Problems

Computational Geometry. Lecture 1: Introduction and Convex Hulls

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

Geometric Algorithms. primitive operations convex hull closest pair voronoi diagram. References: Algorithms in C (2nd edition), Chapters 24-25

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

INTERSECTION OF LINE-SEGMENTS

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA === Homework submission instructions ===

Chapter Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling

Vector storage and access; algorithms in GIS. This is lecture 6

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

Solving Geometric Problems with the Rotating Calipers *

8 Primes and Modular Arithmetic

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

Data Structures and Algorithms Written Examination

Algorithms. Margaret M. Fleck. 18 October 2010

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.

Near Optimal Solutions

Applied Algorithm Design Lecture 5

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

Lecture 4 Online and streaming algorithms for clustering

Chapter 9. Systems of Linear Equations

Kapitel 1 Multiplication of Long Integers (Faster than Long Multiplication)

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

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

Grade 6 Math Circles March 10/11, 2015 Prime Time Solutions

Integers (pages )

3. INNER PRODUCT SPACES

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

#1-12: Write the first 4 terms of the sequence. (Assume n begins with 1.)

CS473 - Algorithms I

z 0 and y even had the form

Well-Separated Pair Decomposition for the Unit-disk Graph Metric and its Applications

Number boards for mini mental sessions

Computational Geometry: Line segment intersection

The finite field with 2 elements The simplest finite field is

Medical Information Management & Mining. You Chen Jan,15, 2013 You.chen@vanderbilt.edu

ARTIFICIAL INTELLIGENCE (CSCU9YE) LECTURE 6: MACHINE LEARNING 2: UNSUPERVISED LEARNING (CLUSTERING)

Minimum Spanning Trees

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

A. The answer as per this document is No, it cannot exist keeping all distances rational.

Everyday Mathematics. Grade 4 Grade-Level Goals CCSS EDITION. Content Strand: Number and Numeration. Program Goal Content Thread Grade-Level Goal

IMPROVING PERFORMANCE OF RANDOMIZED SIGNATURE SORT USING HASHING AND BITWISE OPERATORS

Everyday Mathematics. Grade 4 Grade-Level Goals. 3rd Edition. Content Strand: Number and Numeration. Program Goal Content Thread Grade-Level Goals

Strictly Localized Construction of Planar Bounded-Degree Spanners of Unit Disk Graphs

PYTHAGOREAN TRIPLES KEITH CONRAD

IB Maths SL Sequence and Series Practice Problems Mr. W Name

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Grade 7/8 Math Circles Fall 2012 Factors and Primes

Vocabulary Cards and Word Walls Revised: June 29, 2011

Math 10 - Unit 3 Final Review - Numbers

Common Core Unit Summary Grades 6 to 8

Equations Involving Lines and Planes Standard equations for lines in space

Systems of Linear Equations

Answer: (a) Since we cannot repeat men on the committee, and the order we select them in does not matter, ( )

DATA STRUCTURES USING C

RN-Codings: New Insights and Some Applications

Fast and Robust Normal Estimation for Point Clouds with Sharp Features

Factoring Patterns in the Gaussian Plane

SECTION 10-2 Mathematical Induction

Mathematics of Internet Security. Keeping Eve The Eavesdropper Away From Your Credit Card Information

CS321. Introduction to Numerical Methods

THE NUMBER OF REPRESENTATIONS OF n OF THE FORM n = x 2 2 y, x > 0, y 0

15 Prime and Composite Numbers

Cryptography and Network Security Department of Computer Science and Engineering Indian Institute of Technology Kharagpur

Data Structures and Algorithms

GREATEST COMMON DIVISOR

P13 Route Plan. E216 Distribution &Transportation

Section 9.1 Vectors in Two Dimensions

The Assignment Problem and the Hungarian Method

PURSUITS IN MATHEMATICS often produce elementary functions as solutions that need to be

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

1 Computational Geometry

DATA MINING CLUSTER ANALYSIS: BASIC CONCEPTS

Data Structures for Moving Objects

Lecture 8 : Coordinate Geometry. The coordinate plane The points on a line can be referenced if we choose an origin and a unit of 20

1. Then f has a relative maximum at x = c if f(c) f(x) for all values of x in some

Mathematics. Mathematical Practices

Graphs without proper subgraphs of minimum degree 3 and short cycles

3. Evaluate the objective function at each vertex. Put the vertices into a table: Vertex P=3x+2y (0, 0) 0 min (0, 5) 10 (15, 0) 45 (12, 2) 40 Max

Analysis of Binary Search algorithm and Selection Sort algorithm

Lecture 6 Online and streaming algorithms for clustering

ALGEBRAIC APPROACH TO COMPOSITE INTEGER FACTORIZATION

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Plaxton Routing. - From a peer - to - peer network point of view. Lars P. Wederhake

Topographic Change Detection Using CloudCompare Version 1.0

1 Functions, Graphs and Limits

α = u v. In other words, Orthogonal Projection

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

17 Greatest Common Factors and Least Common Multiples

EdExcel Decision Mathematics 1

Contents. Sample worksheet from

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

11. APPROXIMATION ALGORITHMS

Transcription:

5.4 Closest Pair of Points

Closest Pair of Points Closest pair. 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. fast closest pair inspired fast algorithms for these problems Brute force. Check all pairs of points p and q with Θ(n 2 ) comparisons. -D version. O(n log n) easy if points are on a line. Assumption. No two points have same x coordinate. to make presentation cleaner 23

Closest Pair of Points: First Attempt Divide. Sub-divide region into 4 quadrants. L 24

Closest Pair of Points: First Attempt Divide. Sub-divide region into 4 quadrants. Obstacle. Impossible to ensure n/4 points in each piece. L 25

Closest Pair of Points Algorithm. Divide: draw vertical line L so that roughly ½n points on each side. L 26

Closest Pair of Points Algorithm. Divide: draw vertical line L so that roughly ½n points on each side. Conquer: find closest pair in each side recursively. L 2 2 27

Closest Pair of Points Algorithm. Divide: draw vertical line L so that roughly ½n points on each side. Conquer: find closest pair in each side recursively. Combine: find closest pair with one point in each side. Return best of 3 solutions. seems like Θ(n 2 ) L 8 2 2 28

Closest Pair of Points Find closest pair with one point in each side, assuming that distance < δ. L 2 2 δ = min(2, 2) 29

Closest Pair of Points Find closest pair with one point in each side, assuming that distance < δ. Observation: only need to consider points within δ of line L. L 2 2 δ = min(2, 2) δ 3

Closest Pair of Points Find closest pair with one point in each side, assuming that distance < δ. Observation: only need to consider points within δ of line L. Sort points in 2δ-strip by their y coordinate. 7 L 6 4 5 2 2 3 δ = min(2, 2) 2 δ 3

Closest Pair of Points Find closest pair with one point in each side, assuming that distance < δ. Observation: only need to consider points within δ of line L. Sort points in 2δ-strip by their y coordinate. Only check distances of those within positions in sorted list! 7 L 6 4 5 2 2 3 δ = min(2, 2) 2 δ 32

Closest Pair of Points Def. Let s i be the point in the 2δ-strip, with the i th smallest y-coordinate. Claim. If i j 2, then the distance between s i and s j is at least δ. Pf. 3 39 j No two points lie in same ½δ-by-½δ box. Two points at least 2 rows apart have distance 2(½δ). 2 rows 29 3 ½δ ½δ Fact. Still true if we replace 2 with 7. i 27 28 ½δ 26 25 δ δ 33

Closest Pair Algorithm Closest-Pair(p,, p n ) { Compute separation line L such that half the points are on one side and half on the other side. δ = Closest-Pair(left half) δ 2 = Closest-Pair(right half) δ = min(δ, δ 2 ) Delete all points further than δ from separation line L 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 δ. O(n log n) 2T(n / 2) O(n) O(n log n) O(n) } return δ. 34

Closest Pair of Points: Analysis Running time. T(n) 2T( n/2) + O(n log n) T(n) = O(n log 2 n) Q. Can we achieve O(n log n)? A. Yes. Don't sort points in strip from scratch each time. Each recursive call returns two lists: all points sorted by y coordinate, and all points sorted by x coordinate. Sort by merging two pre-sorted lists. T(n) 2T( n/2) + O(n) T(n) = O(n log n) 35

5.5 Integer Multiplication

37 Integer Arithmetic Add. Given two n-digit integers a and b, compute a + b. O(n) bit operations. Multiply. Given two n-digit integers a and b, compute a b. Brute force solution: Θ(n 2 ) bit operations. * + Add Multiply

Divide-and-Conquer Multiplication: Warmup To multiply two n-digit integers: Multiply four pairs of ½n-digit integers. Add two ½n-digit integers, and shift to obtain result. x = 2 n /2 x + x y = 2 n /2 y + y ( ) ( 2 n /2 y + y ) = 2 n x y + 2 n /2 x y + x y xy = 2 n /2 x + x ( ) + x y ( ) T(n) = 4T n/2 4 243 + Θ(n) 23 T(n) = Θ(n2 ) recursive calls add, shift assumes n is a power of 2 38

Karatsuba Multiplication To multiply two n-digit integers: Add two ½n digit integers. Multiply three ½n-digit integers. Add, subtract, and shift ½n-digit integers to obtain result. Theorem. [Karatsuba-Ofman, 962] Can multiply two n-digit integers x = 2 n /2 x + x y = 2 n /2 y + y xy = 2 n x y + 2 n /2 x y + x y in O(n.585 ) bit operations. ( ) + x y ( ) + x y = 2 n x y + 2 n /2 (x + x )(y + y ) x y x y A B A C C ( ) + T n /2 ( ) + T( + n /2 ) T(n) T n /2 4444444 244444443 recursive calls T(n) = O(n log 2 3 ) = O(n.585 ) + Θ(n) 4 243 add, subtract, shift 39

Karatsuba: Recursion Tree T(n) = if n = 3T(n/2) + n otherwise log 2 n T(n) = n 2 3 = k= ( ) k ( ) +log 2 n 3 2 3 = 3n log2 3 2 2 T(n) n T(n/2) T(n/2) T(n/2) 3(n/2) T(n/4) T(n/4) T(n/4) T(n/4) T(n/4) T(n/4) T(n/4) T(n/4) T(n/4) 9(n/4)...... T(n / 2 k ) 3 k (n / 2 k )...... T(2) T(2) T(2) T(2) T(2) T(2) T(2) T(2) 3 lg n (2) 4