The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d)

Similar documents
Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d)

Algorithms and Data Structures Strassen s Algorithm. ADS (2017/18) Lecture 4 slide 1

CMPSCI611: Three Divide-and-Conquer Examples Lecture 2

Chapter 4 Divide-and-Conquer

Matrix Multiplication

The Divide-and-Conquer Design Paradigm

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

Introduction to Algorithms 6.046J/18.401J/SMA5503

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

Divide-and-conquer algorithm

Inf 2B: Sorting, MergeSort and Divide-and-Conquer

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

Fast Convolution; Strassen s Method

Complexity of Matrix Multiplication and Bilinear Problems

Divide and Conquer. Arash Rafiey. 27 October, 2016

1 Caveats of Parallel Algorithms

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

Linear Methods (Math 211) - Lecture 2

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

1.1 Administrative Stuff

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Grade 11/12 Math Circles Fall Nov. 5 Recurrences, Part 2

Dynamic Programming: Matrix chain multiplication (CLRS 15.2)

Computational Complexity. This lecture. Notes. Lecture 02 - Basic Complexity Analysis. Tom Kelsey & Susmit Sarkar. Notes

Dynamic Programming (CLRS )

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

Computational Complexity - Pseudocode and Recursions

CSE 613: Parallel Programming. Lectures ( Analyzing Divide-and-Conquer Algorithms )

MATH10212 Linear Algebra B Homework Week 5

Lecture 6 & 7. Shuanglin Shao. September 16th and 18th, 2013

COMP 382: Reasoning about algorithms

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Divide and Conquer Algorithms

Ma/CS 6b Class 12: Graphs and Matrices

CSE 613: Parallel Programming. Lecture 8 ( Analyzing Divide-and-Conquer Algorithms )

Outline. 1 Introduction. Merging and MergeSort. 3 Analysis. 4 Reference

We could express the left side as a sum of vectors and obtain the Vector Form of a Linear System: a 12 a x n. a m2

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Methods for solving recurrences

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Powers of Tensors and Fast Matrix Multiplication

Data Structures and Algorithms CMPSC 465

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes )

Determinants of 2 2 Matrices

Matrices: 2.1 Operations with Matrices

CS100: DISCRETE STRUCTURES. Lecture 3 Matrices Ch 3 Pages:

CS483 Design and Analysis of Algorithms

University of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers. Lecture 5

Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201

Design and Analysis of Algorithms

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

Dot Products, Transposes, and Orthogonal Projections

Lecture 9: Submatrices and Some Special Matrices

CSC236 Week 4. Larry Zhang

Divide and Conquer CPE 349. Theresa Migler-VonDollen

cse547, math547 DISCRETE MATHEMATICS Professor Anita Wasilewska

FFT: Fast Polynomial Multiplications

I. Approaches to bounding the exponent of matrix multiplication

Complexity Theory of Polynomial-Time Problems

Lecture 10: Powers of Matrices, Difference Equations

CS 4424 Matrix multiplication

1111: Linear Algebra I

Asymptotic Analysis and Recurrences

Lecture 4: Products of Matrices

COE428 Notes Week 4 (Week of Jan 30, 2017)

A = , A 32 = n ( 1) i +j a i j det(a i j). (1) j=1

Recommended readings: Description of Quicksort in my notes, Ch7 of your CLRS text.

. =. a i1 x 1 + a i2 x 2 + a in x n = b i. a 11 a 12 a 1n a 21 a 22 a 1n. i1 a i2 a in

Introduction to Algorithms

What if the characteristic equation has complex roots?

1300 Linear Algebra and Vector Geometry

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution.

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

CS483 Design and Analysis of Algorithms

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

282 Math Preview. Chris Brown. September 8, Why This? 2. 2 Logarithms Basic Identities Basic Consequences...

Solving Recurrences. Lecture 23 CS2110 Fall 2011

Lecture 6: Lies, Inner Product Spaces, and Symmetric Matrices

ICS141: Discrete Mathematics for Computer Science I

CS 231: Algorithmic Problem Solving

Recurrence Relations

Vector, Matrix, and Tensor Derivatives

Divide and Conquer. Chapter Overview. 1.2 Divide and Conquer

The divide-and-conquer strategy solves a problem by: 1. Breaking it into subproblems that are themselves smaller instances of the same type of problem

Algorithm Design and Analysis

MATH 320, WEEK 7: Matrices, Matrix Operations

CSI2101-W08- Recurrence Relations

Complexity Theory of Polynomial-Time Problems

Mathematics 13: Lecture 10

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version)

Math 4377/6308 Advanced Linear Algebra

Kartsuba s Algorithm and Linear Time Selection

Divide and Conquer Strategy

Matrices BUSINESS MATHEMATICS

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 3. Θ Notation. Comparing Algorithms

MATRIX MULTIPLICATION AND INVERSION

Divide-and-conquer: Order Statistics. Curs: Fall 2017

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

Transcription:

The Master Theorem for solving recurrences lgorithms and Data Structures Strassen s lgorithm 23rd September, 2014 Theorem Let n 0 N, k N 0 and a, b R with a > 0 and b > 1, and let T : N R satisfy the following recurrence: { Θ(1) if n < n 0, T (n) a T (n/b) + Θ(n k ) if n n 0. Let c log b (a); we call c the critical exponent. Then Θ(n c ) if k < c (I), T (n) Θ(n c lg(n)) if k c (II), Θ(n k ) if k > c (III). Theorem also holds if we replace a T (n/b) above by a 1 T ( n/b ) + a 2 T ( n/b ) for any a 1, a 2 0 with a 1 + a 2 a. Start next week (week 3) Tutorials DS (2014/15) Lecture 3 slide 1 Tutorial allocations will soon appear on the course webpage http://www.inf.ed.ac.uk/teaching/courses/ads/ The Master Theorem (cont d) DS (2014/15) Lecture 3 slide 3 We don t have time to prove the Master Theorem in class. You can find the proof in Section 4.6 of [CLRS]. Section 4.4 of [CLRS], 2nd ed. Their version of the M.T. is a bit more general than ours. Consider the following examples: T (n) 4T (n/2) + n, T (n) 4T ( n/2 ) + n 2, T (n) 4T (n/2) + n 3. Could alternatively unfold-and-sum to guess, then prove, the first and third of these. CLSS EXERCISE DS (2014/15) Lecture 3 slide 2 DS (2014/15) Lecture 3 slide 4

Recall Matrix Multiplication The product of two (n n)-matrices (a ij ) 1 i,j n and (b ij ) 1 i,j n is the (n n)-matrix C where C (c ij ) 1 i,j n with entries n c ij a ik b kj. straightforward algorithm lgorithm MatMult(, ) 1. n number of rows of 2. for i 1 to n do 3. for j 1 to n do 4. c ij 0 5. for k 1 to n do 6. c ij c ij + a ik b kj 7. return C (c ij ) 1 i,j n The Matrix Multiplication Problem Input: (n n)-matrices and Output: the (n n)-matrix Requires Θ(n 3 ) arithmetic operations (additions and multiplications). row i c ij Matrix Multiplication column j - n multiplications and n additions for each c ij. - there are n 2 different c ij entries. DS (2014/15) Lecture 3 slide 5 b 1j b2j a i1 a i2 a in b nj DS (2014/15) Lecture 3 slide 7 näive divide-and-conquer algorithm Observe If 11 12 11 12 and 21 22 21 22 for (n/2 n/2)-submatrices ij and ij then 11 11 + 12 21 11 12 + 12 22 21 11 + 22 21 21 12 + 22 22 note: We are assuming n is a power of 2. DS (2014/15) Lecture 3 slide 6 DS (2014/15) Lecture 3 slide 8

row i näive divide-and-conquer algorithm c ij column j 11 12 a i1 a i2 21 22 a in b b 1j 2j 11 12 21 22 b nj Suppose i n/2 and j > n/2. Then n/2 n n c ij a ik b kj a ik b kj + a ik b kj kn/2+1 11 12 12 22 nalysis of D&C-MatMult T (n) is the number of operations done by D&C-MatMult. Lines 1, 2, 3, 4, 7 require Θ(1) arithmetic operations Line 5 requires 8T (n/2) arithmetic operations Line 6 requires 4(n/2) 2 Θ(n 2 ) arithmetic operations. Remember Size of matrices is Θ(n 2 ), NOT Θ(n) We get the recurrence T (n) 8T (n/2) + Θ(n 2 ). Since log 2 (8) 3, the Master Theorem yields T (n) Θ(n 3 ). (No improvement over MatMult... why? CLSS?...) DS (2014/15) Lecture 3 slide 9 näive divide-and-conquer algorithm (cont d) ssume n is a power of 2. lgorithm D&C-MatMult(, ) 1. n number of rows of 2. if n 1 then return (a 11 b 11 ) 3. else 4. Let ij, ij (for i, j 1, 2) be (n/2 n/2)-submatrices s.th. 11 12 11 12 and 21 22 21 22 5. Recursively compute 11 11, 12 21, 11 12, 12 22, 21 11, 22 21, 21 12, 22 22 6. Compute C 11 11 11 + 12 21, C 12 11 12 + 12 22, C 21 21 11 + 22 21, C 22 21 12 + 22 22 C 11 C 12 7. return Strassen s algorithm (1969) DS (2014/15) Lecture 3 slide 11 ssume n is a power of 2. Let 11 12 11 12 and. 21 22 21 22 We want to compute 11 11 + 12 21 11 12 + 12 22 21 11 + 22 21 21 12 + 22 22 C11 C 12. Strassen s algorithm uses a trick in applying Divide-and-Conquer. DS (2014/15) Lecture 3 slide 10 DS (2014/15) Lecture 3 slide 12

Let Then Strassen s algorithm (cont d) P 1 ( 11 + 22 )( 11 + 22 ) P 2 ( 21 + 22 ) 11 P 3 11 ( 12 22 ) P 4 22 ( 11 + 21 ) P 5 ( 11 + 12 ) 22 P 6 ( 11 + 21 )( 11 + 12 ) P 7 ( 12 22 )( 21 + 22 ) C 11 P 1 + P 4 P 5 + P 7 C 12 P 3 + P 5 C 21 P 2 + P 4 C 22 P 1 + P 3 P 2 + P 6 ( ) ( ) Strassen s algorithm (cont d) Crucial Observation Only 7 multiplications of (n/2 n/2)-matrices are needed to compute. lgorithm Strassen(, ) 1. n number of rows of 2. if n 1 then return (a 11 b 11 ) 3. else 4. Determine ij and ij for i, j 1, 2 (as before) 5. Compute P 1,..., P 7 as in ( ) 6. Compute C 11, C 12, C 21, C 22 as in ( ) C11 C 12 7. return DS (2014/15) Lecture 3 slide 13 Checking Strassen s algorithm - C 11 We will check the equation for C 11 is correct. Strassen s algorithm computes C 11 P1 + P4 P5 + P7. We have P1 (11 + 22)(11 + 22) 1111 + 1122 + 2211 + 2222. P4 22( 11 + 21) 2221 2211. P5 (11 + 12)22 1122 + 1222. P7 (12 22)(21 + 22) 1221 + 1222 2221 2222. Then P1 + P4 1111 + 1122 + 2222 + 2221. Then P1 + P4 P5 1111 + 2222 + 2221 1222. Then P1 + P4 P5 + P7 1111 + 1221, which is C11. homework: check other 3 equations. nalysis of Strassen s algorithm DS (2014/15) Lecture 3 slide 15 Let T (n) be the number of arithmetic operations performed by Strassen. Lines 1 4 and 7 require Θ(1) arithmetic operations Line 5 requires 7T (n/2) + Θ(n 2 ) arithmetic operations Line 6 requires Θ(n 2 ) arithmetic operations. remember. We get the recurrence T (n) 7T (n/2) + Θ(n 2 ). Since log 2 (7) 2.807 > 2, the Master Theorem yields T (n) Θ(n log 2 (7) ). DS (2014/15) Lecture 3 slide 14 DS (2014/15) Lecture 3 slide 16

reakthroughs on matrix multiplication Coppersmith & Winograd (1987) came up with an improved algorithm with running time of... many years of silence... Θ(n 2.376 ). Then in his 2010 PhD thesis, ndrew Stothers from the School of Maths, at the University of Edinburgh got an algorithm with Θ(n c ) for c < 2.3737... Coppersmith/Winograd not optimal. ut Stothers didn t publish. Reading ssignment [CLRS] (3rd ed) Section 4.5 The Master method for solving recurrences (Section 4.3 Using the Master method of [CLRS], 2nd ed) [CLRS] (3rd ed) Section 4.2 (Section 28.2 of [CLRS], 2nd ed) Problems 1. Exercise 4.5-2 of [CLRS] (3rd ed) Exercise 4.3-2 of [CLRS], 2nd ed. 2. Exercise 4.2-1 of [CLRS], 3rd ed. Exercise 28.2-1 [CLRS], 2nd ed. 3. Week 3 tutorial sheet :-) In December 2011, Virginia Vassilevska Williams of Stanford, came up with a Θ(n c ) algoithm, for c < 2.3727 (partly, but not only, making use of some of Stothers ideas) Remarks on Matrix Multiplication DS (2014/15) Lecture 3 slide 17 In practice, the school MatMult algorithm tends to outperform Strassen s algorithm, unless the matrices are huge. The best known lower bound for matrix multiplication is DS (2014/15) Lecture 3 slide 19 Ω(n 2 ). This is a trivial lower bound (need to look at all entries of each matrix). mazingly, Ω(n 2 ) is believed to be the truth Open problem: Can we find a O(n 2+o(1) )-algorithm for Matrix Multiplication of n n matrices? DS (2014/15) Lecture 3 slide 18