CSCE 411 Design and Analysis of Algorithms

Slides:



Advertisements
Similar presentations
CPSC 411 Design and Analysis of Algorithms Set 3: Divide and Conquer Prof. Jennifer Welch Spring 2011 CPSC 411, Spring 2011: Set 3 1.
Advertisements

Divide-and-Conquer CIS 606 Spring 2010.
A simple example finding the maximum of a set S of n numbers.
More on Divide and Conquer. The divide-and-conquer design paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
Introduction to Algorithms Jiafen Liu Sept
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.
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
1 Divide-and-Conquer CSC401 – Analysis of Algorithms Lecture Notes 11 Divide-and-Conquer Objectives: Introduce the Divide-and-conquer paradigm Review the.
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
CIT 596 Complexity. Tight bounds Is mergesort O(n 4 )? YES! But it is silly to use that as your measure More common to hear it as….? What about quicksort?
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 4 Some of the sides are exported from different sources.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
5 - 1 § 5 The Divide-and-Conquer Strategy e.g. find the maximum of a set S of n numbers.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
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.
Divide-and-Conquer 7 2  9 4   2   4   7
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
Project 2 due … Project 2 due … Project 2 Project 2.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
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 Andreas Klappenecker [based on slides by Prof. Welch]
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
Lecture 6 Sorting II Divide-and-Conquer Algorithms.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Chapter 4 Divide-and-Conquer
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull
Divide-and-Conquer 6/30/2018 9:16 AM
Unit 1. Sorting and Divide and Conquer
Chapter 4: Divide and Conquer
Lecture 4 Divide-and-Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Divide and Conquer.
Divide-and-Conquer The most-well known algorithm design strategy:
Unit-2 Divide and Conquer
Algorithms and Data Structures Lecture III
Divide-and-Conquer 7 2  9 4   2   4   7
Topic: Divide and Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Introduction to Algorithms
Divide and Conquer Algorithms Part I
Divide-and-Conquer The most-well known algorithm design strategy:
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
Trevor Brown CS 341: Algorithms Trevor Brown
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Richard Anderson Lecture 14 Divide and Conquer
CSC 380: Design and Analysis of Algorithms
Algorithms Recurrences.
Topic: Divide and Conquer
Richard Anderson Lecture 14, Winter 2019 Divide and Conquer
Richard Anderson Lecture 14 Divide and Conquer
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

CSCE 411 Design and Analysis of Algorithms Set 3: Divide and Conquer Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 3

Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively solve subproblems combine solutions to subproblems to get solution to original problem Use recurrences to analyze the running time of such algorithms CSCE 411, Spring 2012: Set 3

Mergesort as D&C Example DIVIDE the input sequence in half RECURSIVELY sort the two halves basis of the recursion is sequence with 1 key COMBINE the two sorted subsequences by merging them CSCE 411, Spring 2012: Set 3

Mergesort Example 5 6 2 1 4 3 5 6 2 4 1 3 6 2 5 2 6 4 1 3 6 2 5 2 4 6 1 3 2 6 2 5 6 4 1 3 6 2 2 6 4 5 1 2 6 3 1 3 2 4 5 6 CSCE 411, Spring 2012: Set 3

Mergesort Animation http://ccl.northwestern.edu/netlogo/models/run.cgi?MergeSort.862.378 CSCE 411, Spring 2012: Set 3

Recurrence Relation for Mergesort Let T(n) be worst case time on a sequence of n keys If n = 1, then T(n) = (1) (constant) If n > 1, then T(n) = 2 T(n/2) + (n) two subproblems of size n/2 each that are solved recursively (n) time to do the merge CSCE 411, Spring 2012: Set 3

How To Solve Recurrences Ad hoc method: expand several times guess the pattern can verify with proof by induction Master theorem general formula that works if recurrence has the form T(n) = aT(n/b) + f(n) a is number of subproblems n/b is size of each subproblem f(n) is cost of non-recursive part CSCE 411, Spring 2012: Set 3

<board work> CSCE 411, Spring 2012: Set 3

Additional D&C Algorithms binary search divide sequence into two halves by comparing search key to midpoint recursively search in one of the two halves combine step is empty quicksort divide sequence into two parts by comparing pivot to each key recursively sort the two parts CSCE 411, Spring 2012: Set 3

Additional D&C Applications computational geometry finding closest pair of points finding convex hull mathematical calculations converting binary to decimal integer multiplication matrix multiplication matrix inversion Fast Fourier Transform CSCE 411, Spring 2012: Set 3

Matrix Multiplication Consider two n by n matrices A and B Definition of AxB is n by n matrix C whose (i,j)-th entry is computed like this: consider row i of A and column j of B multiply together the first entries of the row and column, the second entries, etc. then add up all the products Number of scalar operations (multiplies and adds) in straightforward algorithm is O(n3). Can we do it faster? CSCE 411, Spring 2012: Set 3

Faster Matrix Multiplication Clever idea due to Strassen Start with a recursive version of the straightfoward algorithm divide A, B and C into 4 quadrants compute the 4 quadrants of C by doing 8 matrix multiplications on the quadrants of A and B, plus (n2) scalar operations CSCE 411, Spring 2012: Set 3

Faster Matrix Multiplication Running time of recursive version of straightfoward algorithm is T(n) = 8T(n/2) + (n2) T(2) = (1) where T(n) is running time on an n x n matrix Master theorem gives us: T(n) = (n3) Can we do fewer recursive calls (fewer multiplications of the n/2 x n/2 submatrices)? CSCE 411, Spring 2012: Set 3

Strassen's Matrix Multiplication There is a way to get all the required information with only 7 matrix multiplications, instead of 8. unintuitive Recurrence for new algorithm is T(n) = 7T(n/2) + (n2) solution is T(n) = (nlog 7) = O(n2.81) CSCE 411, Spring 2012: Set 3

<board work> CSCE 411, Spring 2012: Set 3

Discussion of Strassen's Algorithm Not always practical constant factor is larger than for naïve method specially designed methods are better on sparse matrices issues of numerical (in)stability recursion uses lots of space Not the fastest known method Fastest known is O(n2.376) Best lower bound known is only is (n2) CSCE 411, Spring 2012: Set 3