Lecture 33 CSE 331 Nov 19, 2012.

Slides:



Advertisements
Similar presentations
Polygon overlay in double precision arithmetic One example of why robust geometric code is hard to write Jack Snoeyink & Andrea Mantler Computer Science,
Advertisements

Divide-and-conquer: closest pair (Chap.33) Given a set of points, find the closest pair (measured in Euclidean distance) Brute-force method: O(n 2 ). Divide-and-conquer.
Lecture 4 Divide and Conquer for Nearest Neighbor Problem
Lecture 30 CSE 331 Nov 8, HW 7 due today Place Q1, Q2 and Q3 in separate piles I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR.
Chapter 2 Recursive Algorithms. 2 Chapter Outline Analyzing recursive algorithms Recurrence relations Closest pair algorithms Convex hull algorithms Generating.
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Spring 2015 Lecture 5: QuickSort & Selection
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
CS38 Introduction to Algorithms Lecture 7 April 22, 2014.
Lecture 37 CSE 331 Nov 4, Homework stuff (Last!) HW 10 at the end of the lecture Solutions to HW 9 on Monday Graded HW 9 on.
Lecture 28 CSE 331 Nov 9, Flu and HW 6 Graded HW 6 at the END of the lecture If you have the flu, please stay home Contact me BEFORE you miss a.
Lecture 32 CSE 331 Nov 18, HW 8 solutions Friday.
Lecture 31 CSE 331 Nov 16, Jeff is out of town this week No regular recitation or Jeff’s normal office hours I’ll hold extra Question sessions Mon,
Lecture 34 CSE 331 Nov 19, HW 9 due today Q1 in one pile and Q 2+3 in another I will not take any HW after 1:15pm.
Lecture 33 CSE 331 Nov 20, Homeworks Submit HW 9 by 1:10PM HW 8 solutions at the end of the lecture.
Lecture 4: Divide and Conquer III: Other Applications and Examples Shang-Hua Teng.
Lecture 36 CSE 331 Dec 2, Graded HW 8 END of the lecture.
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
1 Comments for Assignment 1 Q1 is basic part and is also part of outcome 1. Q2 is for outcome 1. Q3 is for outcome 2. To pass outcome 1, you need to get.
 x (x 2  0) 1. True2. False.  x (3x + 2 = 12) 1. True2. False.
Lecture 34 CSE 331 Nov 23, Homework related stuff Graded HW 8+9, solutions to HW 9 the week after Thanksgiving.
Lecture 33 CSE 331 Nov 17, Online office hours Alex will host the office hours.
Lecture 30 CSE 331 Nov 10, Online Office Hours
Lecture 29 CSE 331 Nov 11, To be strictly enforced For the rest of the semester on Fridays SUBMIT your HOMEWORKS by 1:10 PM.
Intro to Computer Algorithms Lecture 11 Phillip G. Bradford Computer Science University of Alabama.
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.
Divide-and-Conquer. Outline Introduction Merge Sort Quick Sort Closest pair of points Large integer multiplication.
Lecture 28 CSE 331 Nov 9, Mini project report due WED.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Chapter 2. Divide-and-conquer Algorithms
Lecture 32 CSE 331 Nov 16, 2016.
Lecture 31 CSE 331 Nov 14, 2016.
MA/CSSE 473 Day 16 Answers to your questions Divide and Conquer
Lecture 26 CSE 331 Nov 2, 2016.
Lecture 31 CSE 331 Nov 13, 2017.
Lecture 34 CSE 331 Nov 26, 2012.
Lecture 34 CSE 331 Nov 26, 2012.
Chapter 5 Divide and Conquer
Punya Biswas Lecture 15 Closest Pair, Multiplication
Lecture 33 CSE 331 Nov 18, 2016.
Lecture 33 CSE 331 Nov 17, 2017.
Lecture 30 CSE 331 Nov 11, 2016.
Lecture 26 CSE 331 Nov 1, 2017.
Lecture 27 CSE 331 Nov 3, 2017.
Lecture 32 CSE 331 Nov 14, 2011.
Lecture 29 CSE 331 Nov 8, 2017.
Lecture 28 CSE 331 Nov 7, 2016.
CMPS 3130/6130: Computational Geometry Spring 2017
Lecture 32 CSE 331 Nov 15, 2017.
Lecture 30 CSE 331 Nov 10, 2017.
Lecture 27 CSE 331 Oct 31, 2014.
Lecture 33 CSE 331 Nov 15, 2013.
Lecture 34 CSE 331 Nov 18, 2011.
Lecture 28 CSE 331 Nov 7, 2012.
Lecture 27 CSE 331 Nov 2, 2010.
Lecture 31 CSE 331 Nov 14, 2012.
Lecture 31 CSE 331 Nov 12, 2010.
Lecture 36 CSE 331 Nov 28, 2011.
Lecture 36 CSE 331 Nov 30, 2012.
Lecture 30 CSE 331 Nov 12, 2012.
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Lecture 15, Winter 2019 Closest Pair, Multiplication
Lecture 31 CSE 331 Nov 11, 2011.
Lecture 30 CSE 331 Nov 9, 2011.
Lecture 32 CSE 331 Nov 12, 2014.
Advanced Algorithms Analysis and Design
Lecture 27 CSE 331 Nov 4, 2016.
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)
Lecture 27 CSE 331 Nov 1, 2013.
Presentation transcript:

Lecture 33 CSE 331 Nov 19, 2012

This week Recitation and OH tomorrow canceled Wed-Fri is fall break

Closest pairs of points Input: n 2-D points P = {p1,…,pn}; pi=(xi,yi) d(pi,pj) = ( (xi-xj)2+(yi-yj)2)1/2 Output: Points p and q that are closest

Group Talk time O(n2) time algorithm? 1-D problem in time O(n log n) ?

Sorting to rescue in 2-D? Pick pairs of points closest in x co-ordinate Pick pairs of points closest in y co-ordinate Choose the better of the two

A property of Euclidean distance yj d(pi,pj) = ( (xi-xj)2+(yi-yj)2)1/2 yi xi xj The distance is larger than the x or y-coord difference

Rest of today’s agenda Divide and Conquer based algorithm

Dividing up P Q R First n/2 points according to the x-coord

Recursively find closest pairs Q R δ = min (blue, green)

An aside: maintain sorted lists Px and Py are P sorted by x-coord and y-coord Qx, Qy, Rx, Ry can be computed from Px and Py in O(n) time

An easy case R > δ Q All “crossing” pairs have distance > δ δ = min (blue, green)

Life is not so easy though Q R δ = min (blue, green)

Today’s agenda Taking care of life’s unfairness

Euclid to the rescue (?) d(pi,pj) = ( (xi-xj)2+(yi-yj)2)1/2 yj yi xi The distance is larger than the x or y-coord difference

Life is not so easy though δ Q R > δ > δ > δ δ = min (blue, green)

All we have to do now δ R Q S Figure if a pair in S has distance < δ S δ = min (blue, green)

Assume can be done in O(n) The algorithm so far… O(n log n) + T(n) Input: n 2-D points P = {p1,…,pn}; pi=(xi,yi) Sort P to get Px and Py O(n log n) T(< 4) = c Closest-Pair (Px, Py) T(n) = 2T(n/2) + cn If n < 4 then find closest point by brute-force Q is first half of Px and R is the rest O(n) Compute Qx, Qy, Rx and Ry O(n) (q0,q1) = Closest-Pair (Qx, Qy) O(n log n) overall (r0,r1) = Closest-Pair (Rx, Ry) O(n) δ = min ( d(q0,q1), d(r0,r1) ) O(n) S = points (x,y) in P s.t. |x – x*| < δ return Closest-in-box (S, (q0,q1), (r0,r1)) Assume can be done in O(n)

Rest of today’s agenda Implement Closest-in-box in O(n) time