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

Similar documents
5.4 Closest Pair of Points

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Divide and Conquer 1

CSE 421 Algorithms: Divide and Conquer

Algorithm Design and Analysis

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

Closest Pair of Points. Cormen et.al 33.4

Ch5. Divide-and-Conquer

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

Divide-Conquer-Glue Algorithms

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.

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

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

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

Lecture 4 CS781 February 3, 2011

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

Divide-and-Conquer Algorithms

CSC Design and Analysis of Algorithms

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

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

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

1 Closest Pair Problem

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

Union Find. Data Structures and Algorithms Andrei Bulatov

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

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn

Divide and Conquer 4-0

Randomized algorithms. Inge Li Gørtz

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk

CS473 - Algorithms I

Algorithms: Lecture 7. Chalmers University of Technology

Test 1 Review Questions with Solutions

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

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

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

Divide-and-Conquer. Dr. Yingwu Zhu

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1

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

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

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

Divide and Conquer. Design and Analysis of Algorithms Andrei Bulatov

Divide and Conquer. Algorithm D-and-C(n: input size)

Back to Sorting More efficient sorting algorithms

Master Theorem, Introduction to Graphs

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

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

The divide-and-conquer paradigm involves three steps at each level of the recursion: Divide the problem into a number of subproblems.

CMPSCI 311: Introduction to Algorithms Practice Final Exam

Divide and Conquer. Divide and Conquer

COMP Analysis of Algorithms & Data Structures

Divide and Conquer. Algorithm Fall Semester

Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn

Algorithms + Data Structures Programs

Divide-and-Conquer CSE 680

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

Geometric Computation: Introduction. Piotr Indyk

Fundamental problem in computing science. putting a collection of items in order. Often used as part of another algorithm

EECS 2011M: Fundamentals of Data Structures

Lecture 2: Divide and Conquer

Data Structures and Algorithms CSE 465

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

CSE 5311 Notes 13: Computational Geometry

Jana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

Lecture 2: Getting Started

Parallel Algorithms for (PRAM) Computers & Some Parallel Algorithms. Reference : Horowitz, Sahni and Rajasekaran, Computer Algorithms

We can use a max-heap to sort data.

Algorithms - Ch2 Sorting

Plotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1

Theorem 2.9: nearest addition algorithm

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.

CPSC W2 Midterm #2 Sample Solutions

The divide and conquer strategy has three basic parts. For a given problem of size n,

Greedy algorithms is another useful way for solving optimization problems.

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

6. Concluding Remarks

Algorithms (IX) Guoqiang Li. School of Software, Shanghai Jiao Tong University

List Ranking. Chapter 4

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.

The complexity of Sorting and sorting in linear-time. Median and Order Statistics. Chapter 8 and Chapter 9

List Ranking. Chapter 4

Graduate Algorithms CS F-19 Computational Geometry

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

Lecture 9: Sorting Algorithms

SORTING AND SELECTION

100 points total. CSE 3353 Homework 2 Spring 2013

Computational Geometry

CS Divide and Conquer

Introduction to Algorithms

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Lecture 15 : Review DRAFT

Programming II (CS300)

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

COT5405: GEOMETRIC ALGORITHMS

Analysis of Algorithms - Quicksort -

26 The closest pair problem

CPSC 320 Midterm 2 Thursday March 13th, 2014

4. Sorting and Order-Statistics

Transcription:

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication Shayan Oveis Gharan 1

Finding the Closest Pair of Points

Closest Pair of Points (non geometric) Given n points and arbitrary distances between them, find the closest pair. (E.g., think of distance as airfare definitely not Euclidean distance!) ( and all the rest of the ( n ) edges ) 2 Must look at all n choose 2 pairwise distances, else any one you didn t check might be the shortest. i.e., you have to read the whole input

Closest Pair of Points (1-dimension) Given n points on the real line, find the closest pair, e.g., given 11, 2, 4, 19, 4.8, 7, 8.2, 16, 11.5, 13, 1 find the closest pair 1 2 4 4.8 7 8.2 11 11.5 13 16 19 Fact: Closest pair is adjacent in ordered list So, first sort, then scan adjacent pairs. Time O(n log n) to sort, if needed, Plus O(n) to scan adjacent pairs Key point: do not need to calc distances between all pairs: exploit geometry + ordering

Closest Pair of Points (2-dimensions) 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. Brute force: Check all pairs of points p and q with (n 2 ) time. Assumption: No two points have same x coordinate.

A Divide and Conquer Alg Divide: draw vertical line L with n/2 points on each side. Conquer: find closest pair on each side, recursively. Combine to find closest pair overall Return best solutions seems like (n 2 )? L 8 21 12

Key Observation Suppose δ is the minimum distance of all pairs in left/right of L. δ = min 12,21 = 12. Key Observation: suffices to consider points within of line L. Almost the one-d problem again: Sort points in 2 -strip by their y coordinate. Only check pts within 11 in sorted list! 7 6 L 4 5 21 12 3 2 1 =12

Almost 1D Problem Partition each side of L into δ 2 δ 2 squares Claim: No two points lie in the same δ 2 δ 2 box. Pf: Such points would be within 39 j δ 2 2 + δ 2 2 = δ 1 2 0.7δ < δ 31 Let s i have the i th smallest y-coordinate among points in the 2δ-width-strip. Claim: If i j > 11, then the distance i 29 27 30 28 29 ½ ½ between s i and s j is > δ. Pf: only 11 boxes within of y(s i ). 26 25

Closest Pair (2Dim Algorithm) Closest-Pair(p 1,, p n ) { if(n <=??) return?? Compute separation line L such that half the points are on one side and half on the other side. 1 = Closest-Pair(left half) 2 = Closest-Pair(right half) = min( 1, 2 ) Delete all points further than from separation line L Sort remaining points p[1] p[m] by y-coordinate. for i = 1..m i for k = 1 11 if i+k <= m = min(, distance(p[i], p[i+k])); } return.

Closest Pair Analysis I Let D(n) be the number of pairwise distance calculations in the Closest-Pair Algorithm when run on n 1 points 1 if n = 1 D n ቐ 2D n D n = O(nlog n) + 11 n o. w. 2 BUT, that s only the number of distance calculations What if we counted running time? 1 if n = 1 T n ቐ 2T n + O(n log n) 2 o. w. D n = O(nlog2 n)

Can we do better? (Analysis II) Yes!! Don t sort by y-coordinates each time. Sort by x at top level only. This is enough to divide into two equal subproblems in O(n) Each recursive call returns and list of all points sorted by y Sort points by y-coordinate by merging two pre-sorted lists. 1 if n = 1 T n ቐ 2T n + O n 2 o. w. D n = O(n log n)

Recurrences Above: Where they come from, how to find them Next: how to solve them

Master Theorem Suppose T n = a T n b + cnk for all n > b. Then, If a > b k then T n = Θ n log ba If a < b k then T n = Θ n k If a = b k then T n = Θ n k log n Works even if it is n b instead of n b. We also need a 1, b > 1, k 0 and T n = O(1) for n b.

Master Theorem Suppose T n = a T n + b cnk for all n > b. Then, If a > b k then T n = Θ n log ba If a < b k then T n = Θ n k If a = b k then T n = Θ n k log n Example: For mergesort algorithm we have T n = 2T n + O n. 2 So, k = 1, a = b k and T n = Θ(n log n)

Proving Master Theorem Problem size n T(n) = at(n/b) + cn k a # probs 1 cost cn k n/b a c a n k /b k n/b 2 b 1 a 2 a d c a 2 n k /b 2k =c n k (a/b k ) 2 c n k (a/b k ) d d=log b n T n = a i c n k i=0 b i

A Useful Identity Theorem: 1 + x + x 2 + + x d = xd+1 1 x 1 Pf: Let S = 1 + x + x 2 + + x d Then, xs = x + x 2 + + x d+1 So, xs S = x d+1 1 i.e., S x 1 = x d+1 1 Therefore, S = xd+1 1 x 1

Solve: T n = at n b + cnk, a > b k b k log b n log b n T n = a i c n k i=0 b i = cn k log b n a i=0 b k = cn k a b k i log b n+1 1 a b k 1 a b k a 1 alogb n x k+1 1 = b log n k b n k = n k c b k log b n b k a log b n 2c a log b n = O(n log b a ) for x = a b k using x 1 x 1 = (b log b a ) log b n = (b log b n ) log b a = n log b a

Solve: T n = at n b + cnk, a = b k log b n T n = a i c n k i=0 b i = cn k log b n a i=0 b k = cn k log b n i

Master Theorem Suppose T n = a T n b + cnk for all n > b. Then, If a > b k then T n = Θ n log ba If a < b k then T n = Θ n k If a = b k then T n = Θ n k log n Works even if it is n b instead of n b. We also need a 1, b > 1, k 0 and T n = O(1) for n b.