Chapter 5 Divide and Conquer

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

Advanced Algorithms Piyush Kumar (Lecture 12: Parallel Algorithms) Welcome to COT5405 Courtesy Baker 05.
Lecture 4 Divide and Conquer for Nearest Neighbor Problem
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.
DIVIDE AND CONQUER. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
The Divide-and-Conquer Strategy
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 11.
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.
Algorithm Design Techniques: Divide and Conquer. Introduction Divide and conquer – algorithm makes at least two recursive calls Subproblems should not.
1 Divide-and-Conquer Divide-and-conquer. n Break up problem into several parts. n Solve each part recursively. n Combine solutions to sub-problems into.
Advanced Algorithm Design and Analysis (Lecture 10) SW5 fall 2004 Simonas Šaltenis E1-215b
CS38 Introduction to Algorithms Lecture 7 April 22, 2014.
1 Lecture 8: Voronoi Diagram Computational Geometry Prof. Dr. Th. Ottmann Voronoi Diagrams Definition Characteristics Size and Storage Construction Use.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
10/2/20061 Algorithms on grids Natasha Gelfand Geometry Seminar Fall 2006.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
Lecture 4: Divide and Conquer III: Other Applications and Examples Shang-Hua Teng.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Linear Time Selection These lecture slides are adapted from CLRS 10.3.
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.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 12.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
9/10/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURES Divide.
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 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Divide and Conquer Applications Sanghyun Park Fall 2002 CSE, POSTECH.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 11.
CSCI 256 Data Structures and Algorithm Analysis Lecture 10 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Recursion.
Advanced Algorithms Analysis and Design
Chapter 2 Divide-and-Conquer algorithms
Chapter 5 Divide and Conquer
Rank Rank of an element is its position in ascending key order.
Chapter 2 Divide-and-Conquer algorithms
Chapter 4 Divide-and-Conquer
Chapter 2 Divide-and-Conquer algorithms
CSCE350 Algorithms and Data Structure
Jordi Cortadella and Jordi Petit Department of Computer Science
Divide and Conquer – and an Example QuickSort
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
Divide-and-Conquer Divide-and-conquer.
Dr. Yingwu Zhu Chapter 9, p Linear Time Selection Dr. Yingwu Zhu Chapter 9, p
Punya Biswas Lecture 15 Closest Pair, Multiplication
Chapter 6 Dynamic Programming
Chapter 6 Dynamic Programming
Master Theorem Yin Tat Lee
Richard Anderson Lecture 13 Divide and Conquer
cse 521: design and analysis of algorithms
Divide-and-Conquer.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Chapter 4 Divide-and-Conquer
Divide and Conquer / Closest Pair of Points Yin Tat Lee
Divide-and-Conquer The most-well known algorithm design strategy:
CSE 373 Data Structures and Algorithms
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Lecture 15, Winter 2019 Closest Pair, Multiplication
Copyright © 2008 Pearson Education, Inc
Introduction to Algorithms
Algorithms and Data Structures Lecture XIV
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)
Richard Anderson Lecture 13 Divide and Conquer
Presentation transcript:

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

Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common usage. Break up problem of size n into two equal parts of size ½n. Solve two parts recursively. Combine two solutions into overall solution in linear time. Consequence. Brute force: n2. Divide-and-conquer: n log n. Divide et impera. Veni, vidi, vici. - Julius Caesar

Closest Pair of Points From the book by Kleinberg and Tardos "Divide and conquer", Caesar's other famous quote "I came, I saw, I conquered" Divide-and-conquer idea dates back to Julius Caesar. Favorite war tactic was to divide an opposing army in two halves, and then assault one half with his entire force.

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. Brute force. Check all pairs of points p and q with (n2) comparisons. 1-D version. O(n log n) easy if points are on a line. Assumption. No two points have same x coordinate. Foundation of then-fledgling field of computational geometry. "Shamos and Hoey (1970's) wanted to work out basic computational primitives in computational geometry. Surprisingly challenging to find an efficient algorithm. Shamos and Hoey asked whether it was possible to do better than quadratic. The algorithm we present is essentially their solution." fast closest pair inspired fast algorithms for these problems to make presentation cleaner

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

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

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

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 21 12

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 (n2) L 8 21 12

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

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 21  = min(12, 21) 12 

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. L 7 6 21 5 4  = min(12, 21) 12 3 2 1 

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 11 positions in sorted list! L 7 6 21 5 4  = min(12, 21) 12 3 2 1 

Closest Pair of Points Def. Let si be the point in the 2-strip, with the ith smallest y-coordinate. Claim. If |i – j|  12, then the distance between si and sj is at least . Pf. No two points lie in same ½-by-½ box. Two points at least 2 rows apart have distance  2(½). ▪ Fact. Still true if we replace 12 with 7. j 39 31 ½ can reduce neighbors to 6 Note: no points on median line (assumption that no points have same x coordinate ensures that median line can be drawn in this way) 2 rows 30 ½ 29 i ½ 28 27 26 25  

Closest Pair Algorithm Closest-Pair(p1, …, pn) { 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 by y-coordinate. Scan points in y-order and compare distance between each point and next 11 neighbors. If any of these distances is less than , update . return . } O(n log n) 2T(n / 2) O(n) separation can be done in O(N) using linear time median algorithm O(n log n) O(n)

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