Advanced Algorithm Design and Analysis (Lecture 10) SW5 fall 2004 Simonas Šaltenis E1-215b

Slides:



Advertisements
Similar presentations
Algorithms and Data Structures Lecture III
Advertisements

Lecture 3: Parallel Algorithm Design
A simple example finding the maximum of a set S of n numbers.
Jarvis March Graham Scan Chan’s Algorithm
1/13/15CMPS 3130/6130: Computational Geometry1 CMPS 3130/6130: Computational Geometry Spring 2015 Convex Hulls Carola Wenk.
Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
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.
Advanced Algorithm Design and Analysis (Lecture 6) SW5 fall 2004 Simonas Šaltenis E1-215b
Lecture 4 Divide and Conquer for Nearest Neighbor Problem
Divide-and-Conquer The most-well known algorithm design strategy:
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. Problem Reduction Dr. M. Sakalli Marmara Unv, Levitin ’ s notes.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
1 Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
CS4413 Divide-and-Conquer
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
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.
The Divide-and-Conquer Strategy
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro.
Theory of Algorithms: Divide and Conquer
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Divide and Conquer.
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
Computational Geometry
8/29/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk.
Informal Definition : Let S is set of nails sticking out from a board. the convex hull can be visualized as the shape formed by a tight rubber band that.
Chapter 4 Divide-and-Conquer Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem.
November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Chapter 4 Divide-and-Conquer Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
UMass Lowell Computer Science Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2007 Lecture 3 Chapter 3: 2D Convex Hulls Friday,
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
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.
5 - 1 § 5 The Divide-and-Conquer Strategy e.g. find the maximum of a set S of n numbers.
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
AALG, lecture 11, © Simonas Šaltenis, Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees and.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2004 Simonas Šaltenis E1-215b
Convex Hull. What is the Convex Hull? Imagine a set of points on a board with a nail hammered into each point. Now stretch a rubber band over all the.
Computational Geometry (35/33) Line Segments and cross-product Segment intersection and Sweep Line Convex Hull and Graham’s Scan, Jarvis’s march Divide-and-Conquer.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
1 Designing algorithms There are many ways to design an algorithm. Insertion sort uses an incremental approach: having sorted the sub-array A[1…j - 1],
September 29, Algorithms and Data Structures Lecture V Simonas Šaltenis Aalborg University
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 Applications Sanghyun Park Fall 2002 CSE, POSTECH.
Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2004 Simonas Šaltenis E1-215b
Convex Hull. University of Manchester biologists used lasers to measure the minimum amount of skin required to wrap around the skeletons of modern-day.
Divide-and-Conquer. Outline Introduction Merge Sort Quick Sort Closest pair of points Large integer multiplication.
Lecture # 6 1 Advance Analysis of Algorithms. Divide-and-Conquer Divide the problem into a number of subproblems Similar sub-problems of smaller size.
Lecture 6 Sorting II Divide-and-Conquer Algorithms.
Advanced Algorithms Analysis and Design
Chapter 4 Divide-and-Conquer
Unit 1. Sorting and Divide and Conquer
Introduction to the Design and Analysis of Algorithms
Chapter 4 Divide-and-Conquer
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Chapter 4 Divide-and-Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
Convex Hulls Given a set of points (x1,y1),(x2,y2),…,(xn,yn), the convex hull is the smallest convex polygon containing all the points.
CMPS 3120: Computational Geometry Spring 2013
Algorithms and Data Structures Lecture XIV
Presentation transcript:

Advanced Algorithm Design and Analysis (Lecture 10) SW5 fall 2004 Simonas Šaltenis E1-215b

AALG, lecture 10, © Simonas Šaltenis, Computational geometry Main goals of the lecture: to understand the concept of output-sensitive algorithms; to be able to apply the divide-and-conquer algorithm design technique to geometric problems; to remember how recurrences are used to analyze the divide-and-conquer algorithms; to understand and be able to analyze the Jarvis’s march and the divide-and-conquer closest-pair algorithms.

AALG, lecture 10, © Simonas Šaltenis, Size of the output In computational geometry, the size of an algorithm’s output may differ/depend on the input. Line-intersection problem vs. convex-hull problem Observation: Graham’s scan running time depends only on the size of the input – it is independent of the size of the output

AALG, lecture 10, © Simonas Šaltenis, Gift wrapping Would be nice to have an algorithm that runs fast if the convex hull is small Idea: gift wrapping (a.k.a Jarvis’s march) 1. Start with the lowest point a, include it in the convex hull 2. The next point in the convex hull has to be in the clockwise direction with respect to all other points looking from the current point on the convex hull 3. Repeat 2. until a is reached. a a a

AALG, lecture 10, © Simonas Šaltenis, Jarvis’s march How many cross products are computed for this example? The running time of Jarvis’s march: Find lowest point – O(n) For each vertex in the convex hull: n–1 cross-product computations Total: O(nh), where h is the number of vertices in the convex hull

AALG, lecture 10, © Simonas Šaltenis, Output-sensitive algorithms Output-sensitive algorithm: its running time depends on the size of the output. When should we use Jarvi’s march instead of the Graham’s scan? The asymptotically optimal output-sensitive algorithm of Kirkpatrick and Seidel runs in O(n lg h)

AALG, lecture 10, © Simonas Šaltenis, Closest-pair problem Given a set P of n points, find p,q P, such that the distance d(p, q) is minimum Checking the distance between two points is O(1) What is the brute-force algorithm and it’s running time?

AALG, lecture 10, © Simonas Šaltenis, Steps of Divide-and-Conquer What are the steps of a divide-and- conquer algorithm? If trivial (small), solve it “brute force” Else 1.divide into a number of sub-problems 2.solve each sub-problem recursively 3.combine solutions to sub-problems

AALG, lecture 10, © Simonas Šaltenis, Dividing into sub-problems How do we divide into sub-problems? Idea: Sort on x-coordinate, and divide into left and right parts: p 1 p 2... p n/2... p n/ p n Solve recursively the left sub-problem P l (closest-pair distance d l ) and the right sub-problem P r (distance d r )

AALG, lecture 10, © Simonas Šaltenis, Combining two solutions How do we combine two solutions to sub- problems? Let d = min{d l, d r } Observation 1: We already have the closest pair where both points are either in the left or in the right sub-problem, we have to check pairs where one point is from one sub-problem and another from the other. Observation 2: Such closest-pair can only be somewhere in a strip of width 2d around the dividing line! Otherwise the points would be more than d units apart.

AALG, lecture 10, © Simonas Šaltenis, Combining two solutions Combining solutions: Finding the closest pair (, ) in a strip of width 2d, knowing that no (, ) or (, ) pair is closer than d

AALG, lecture 10, © Simonas Šaltenis, Combining Two Solutions Do we have to check all pairs of points in the strip? For a given point p from one partition, where can there be a point q from the other partition, that can form the closest pair with p? In the dd square: How many points can there be in this square? At most 4! p

AALG, lecture 10, © Simonas Šaltenis, Combining two solutions Algorithm for checking the strip: Sort all the points in the strip on the y- coordinate For each point p only 7 points ahead of it in the order have to be checked to see if any of them is closer to p than d p

AALG, lecture 10, © Simonas Šaltenis, Pseudocode What is the trivial problem? That is – when do we stop recursion? Closest-Pair(P, l, r) // First call: an array P of points sorted on x-coordinate, 1, n 01 if r – l < 3 then return Brute-Force-CPair(P, l, r) 02 q   (l+r)/2  03 dl  Closest-Pair(P, l, q-1) 04 dr  Closest-Pair(P, q, r) 05 d  min(dl, dr) 06 for i  l to r do 07 if P[q].x - d  P[i].x  P[q].x + d then 08 append P[i] to S 09 Sort S on y-coordinate 10 for j  1 to size_of(S)-1 do 11 Check if any of d(S[j],S[j]+1),..., d(S[j],S[j]+7) is smaller than d, if so set d to the smallest of them 12 return d

AALG, lecture 10, © Simonas Šaltenis, Example How many distance computations are done in this example?

AALG, lecture 10, © Simonas Šaltenis, Running time What is the running time of this algorithm? Running time of a divide-and-conquer algorithm can be described by a recurrence Divide = O(1) Combine = O(n lg n) This gives the following recurrence: Total running time: O(n log 2 n) Better than brute force, but…

AALG, lecture 10, © Simonas Šaltenis, Improving the running time How can we improve the running time of the algorithm? Idea: Sort all the points by x and y coordinate once Before recursive calls, partition the sorted lists into two sorted sublists for the left and right halves: O(n) When combining, run through the y-sorted list once and select all points that are in a 2d strip around partition line: O(n) How does the new recurrence look like and what is its solution?

AALG, lecture 10, © Simonas Šaltenis, Conclusion The closest pair can be found in O(n log n) time with divide-and-conquer algorithm Plane-sweep algorithm with the same asymptotic running time exists This is asymptotically optimal

AALG, lecture 10, © Simonas Šaltenis, Exercise: Convex-hull Let’s find the convex-hull using divide-and- conquer What is a trivial problem and how we solve it? How do we divide the problem into sub- problems? How do we combine solutions to sub-problems?

AALG, lecture 10, © Simonas Šaltenis, Repeated Substitution Solving recurrences by repeated substitution:

AALG, lecture 10, © Simonas Šaltenis, Repeated Substitution Method The procedure is straightforward: Substitute Expand Substitute Expand … Observe a pattern and write how your expression looks after the i-th substitution Find out what the value of i (e.g., lg n) should be to get the base case of the recurrence (say T(1)) Insert the value of T(1) and the expression of i into your expression