CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 16.

Slides:



Advertisements
Similar presentations
Divide-and-Conquer CIS 606 Spring 2010.
Advertisements

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.
Divide-and-Conquer The most-well known algorithm design strategy:
DIVIDE AND CONQUER. 2 Algorithmic Paradigms Greedy. Build up a solution incrementally, myopically optimizing some local criterion. Divide-and-conquer.
Dr. Deshi Ye Divide-and-conquer Dr. Deshi Ye
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Strassen's Matrix Multiplication Sibel KIRMIZIGÜL.
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 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.
Lecture 10 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
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.
Introduction to Algorithms 6.046J/18.401J L ECTURE 3 Divide and Conquer Binary search Powering a number Fibonacci numbers Matrix multiplication Strassen’s.
Lecture 2: Divide and Conquer algorithms Phan Thị Hà Dương
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
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.
Notes on the analysis of multiplication algorithms.. Dr. M. Sakalli, Marmara University.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fast Fourier Transform Jean Baptiste Joseph Fourier ( ) These lecture.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
Arithmetic.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 12.
Divide-and-Conquer 7 2  9 4   2   4   7
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.
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
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.
5.6 Convolution and FFT. 2 Fast Fourier Transform: Applications Applications. n Optics, acoustics, quantum physics, telecommunications, control systems,
1 Chapter 4 Divide-and-Conquer. 2 About this lecture Recall the divide-and-conquer paradigm, which we used for merge sort: – Divide the problem into a.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
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.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
1 Chapter 4-2 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
ADA: 4.5. Matrix Mult.1 Objective o an extra divide and conquer example, based on a question in class Algorithm Design and Analysis (ADA) ,
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Introduction: Efficient Algorithms for the Problem of Computing Fibonocci Numbers Prepared by John Reif, Ph.D. Analysis of Algorithms.
1 Chapter 5 Divide and Conquer Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
1 Complete this to a Pfaffian orientation (all internal faces have an odd number of clockwise arcs).
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 11.
Divide and Conquer Faculty Name: Ruhi Fatima Topics Covered Divide and Conquer Matrix multiplication Recurrence.
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.
MA/CSSE 473 Day 14 Strassen's Algorithm: Matrix Multiplication Decrease and Conquer DFS.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Chapter 2 Divide-and-Conquer algorithms
Chapter 2 Divide-and-Conquer algorithms
Chapter 4 Divide-and-Conquer
Chapter 2 Divide-and-Conquer algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Algorithms with numbers (1) CISC4080, Computer Algorithms
CSCE 411 Design and Analysis of Algorithms
Punya Biswas Lecture 15 Closest Pair, Multiplication
Introduction to Algorithms
Divide and Conquer Neil Tang 4/24/2008
CSCI 256 Data Structures and Algorithm Analysis Lecture 12
Comments from last time
Lecture 15, Winter 2019 Closest Pair, Multiplication
Topic: Divide and Conquer
Lecture 15 Closest Pair, Multiplication
Presentation transcript:

CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 16

Integer Arithmetic Add: Given two n-digit integers a and b, compute a + b –O(n) bit operations Multiply: Given two n-digit integers a and b, compute a × b –Brute force solution:  (n 2 ) bit operations Add Multiply

Divide-and-Conquer Multiplication: Warmup To multiply two n-digit integers –Multiply four ½n-digit integers –Add two ½n-digit integers, and shift to obtain result assumes n is a power of 2

Karatsuba Multiplication To multiply two n-digit integers –Add two ½n digit integers –Multiply three ½n-digit integers –Add, subtract, and shift ½n-digit integers to obtain result

Karatsuba Multiplication Recursive-Multiply (x, y) Write x = x 1  2 n/2 + x 0 y = y 1  2 n/2 + y 0 Compute x 1 + x 0 and y 1 + y 0 p = Recursive-Multiply(x 1 + x 0, y 1 + y 0 ) x 1 y 1 = Recursive-Multiply(x 1, y 1 ) x 0 y 0 = Recursive-Multiply(x 0, y 0 ) Return x 1 y 1  2 n + (p - x 1 y 1 - x 0 y 0 )  2 n/2 + x 0 y 0

Karatsuba Multiplication Theorem: [Karatsuba-Ofman, 1962] Can multiply two n-digit integers in O(n ) bit operations

Karatsuba: Recursion Tree n 3(n/2) 9(n/4) 3 k (n / 2 k ) 3 lg n (2)... T(n) T(n/2) T(n/4) T(2) T(n / 2 k ) T(n/4) T(n/2) T(n/4) T(n/2) T(n/4)...

Matrix Multiplication Matrix multiplication: Given two n-by-n matrices A and B, compute C = AB Brute force:  (n 3 ) arithmetic operations Fundamental question: Can we improve upon brute force?

Matrix Multiplication: Warmup Divide-and-conquer –Divide: partition A and B into ½n-by-½n blocks –Conquer: multiply 8 ½n-by-½n recursively –Combine: add appropriate products using 4 matrix additions

Matrix Multiplication: Key Idea Key idea: multiply 2-by-2 block matrices with only 7 multiplications 7 multiplications 18 = additions (or subtractions)

Fast Matrix Multiplication Fast matrix multiplication (Strassen, 1969) –Divide: partition A and B into ½n-by-½n blocks –Compute: 14 ½n-by-½n matrices via 10 matrix additions –Conquer: multiply 7 ½n-by-½n matrices recursively –Combine: 7 products into 4 terms using 8 matrix additions Analysis –Assume n is a power of 2 –T(n) = # arithmetic operations

Fast Matrix Multiplication in Practice Implementation issues –Sparsity –Numerical stability –Odd matrix dimensions Common misperception: "Strassen is only a theoretical curiosity.“ –Advanced Computation Group at Apple Computer reports 8x speedup on G4 Velocity Engine when n ~ 2,500 –Range of instances where it's useful is a subject of controversy

Fast Matrix Multiplication in Theory Decimal wars –December, 1979: O(n ) –January, 1980: O(n ) Best known: O(n ) [Coppersmith-Winograd, 1987] Conjecture: O(n 2+  ) for any  > 0