Matrix Multiplication. Data Structures and Algorithms Andrei Bulatov

Similar documents
Matrix Multiplication

Algorithms Design & Analysis. Divide & Conquer

Copyright 2000, Kevin Wayne 1

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

CS 580: Algorithm Design and Analysis

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

Divide and Conquer II

Recurrence Relations

Dynamic Programming 1

Divide and Conquer Dynamic Programming Greedy Algorithm

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Model of Computation and Runtime Analysis

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

Model of Computation and Runtime Analysis

Copyright 2000, Kevin Wayne 1

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

Dynamic Programming: Interval Scheduling and Knapsack

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ.

CSE 421 Dynamic Programming

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

Polynomial Multiplication and Fast Fourier Transform

2 DD2458 Popup HT Solution: Choose the activity which ends first and does not conflict with earlier chosen activities.

6. DYNAMIC PROGRAMMING I

Data Structures Lecture 9

CS 5150/6150: Assignment 1 Due: Sep 23, 2010

Design and Analysis of Algorithms

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Merge and Quick Sort

Advanced Course of Algorithm Design and Analysis

Dynamic Programming. Weighted Interval Scheduling. Algorithmic Paradigms. Dynamic Programming

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University

Algorithms and Data Structures Lecture IV

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

Dynamic Programming. Sequence Of Decisions

Dynamic Programming. Sequence Of Decisions. 0/1 Knapsack Problem. Sequence Of Decisions

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

Hashing and Amortization

Areas. ! Bioinformatics. ! Control theory. ! Information theory. ! Operations research. ! Computer science: theory, graphics, AI, systems,.

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

Algorithms 演算法. Multi-threaded Algorithms

2. ALGORITHM ANALYSIS

CS / MCS 401 Homework 3 grader solutions

Chapter 6. Dynamic Programming. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

4.3 Growth Rates of Solutions to Recurrences

Orthogonal transformations

For a 3 3 diagonal matrix we find. Thus e 1 is a eigenvector corresponding to eigenvalue λ = a 11. Thus matrix A has eigenvalues 2 and 3.

Lecture 3: Divide and Conquer: Fast Fourier Transform

Trial division, Pollard s p 1, Pollard s ρ, and Fermat s method. Christopher Koch 1. April 8, 2014

1 Last time: similar and diagonalizable matrices

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

6.003 Homework #3 Solutions

Ch3. Asymptotic Notation

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

Analysis of Algorithms -Quicksort-

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture)

Chapter 22 Developing Efficient Algorithms

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

Generating Functions. 1 Operations on generating functions

ECE 308 Discrete-Time Signals and Systems

Test One (Answer Key)

CSE Introduction to Parallel Processing. Chapter 3. Parallel Algorithm Complexity

SECTION 1.5 : SUMMATION NOTATION + WORK WITH SEQUENCES

A Probabilistic Analysis of Quicksort

CSE 1400 Applied Discrete Mathematics Number Theory and Proofs

MA131 - Analysis 1. Workbook 3 Sequences II

CSE 417, Winter Greedy Algorithms

CHAPTER I: Vector Spaces

Let us consider the following problem to warm up towards a more general statement.

Copyright 2000, Kevin Wayne 1

Lesson 10: Limits and Continuity

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS

Dynamic Programming. Cormen et. al. IV 15

Chapter 6 Principles of Data Reduction

YALE UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE

CSE 202 Dynamic Programming II

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Divide-and-Conquer

Chapter 4. Fourier Series

PAPER : IIT-JAM 2010

THE SOLUTION OF NONLINEAR EQUATIONS f( x ) = 0.

Rouché s Theorem 7/13/2011

6 Integers Modulo n. integer k can be written as k = qn + r, with q,r, 0 r b. So any integer.

In number theory we will generally be working with integers, though occasionally fractions and irrationals will come into play.

NUMERICAL METHODS FOR SOLVING EQUATIONS

CS161 Design and Analysis of Algorithms. Administrative

IP Reference guide for integer programming formulations.

Intensive Algorithms Lecture 11. DFT and DP. Lecturer: Daniel A. Spielman February 20, f(n) O(g(n) log c g(n)).

Parallel Vector Algorithms David A. Padua

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability.

Algebra II Notes Unit Seven: Powers, Roots, and Radicals

2.1. The Algebraic and Order Properties of R Definition. A binary operation on a set F is a function B : F F! F.

10.1 Sequences. n term. We will deal a. a n or a n n. ( 1) n ( 1) n 1 2 ( 1) a =, 0 0,,,,, ln n. n an 2. n term.

CS 332: Algorithms. Quicksort

Olli Simula T / Chapter 1 3. Olli Simula T / Chapter 1 5

Fall 2013 MTH431/531 Real analysis Section Notes

Analysis of Algorithms. Introduction. Contents

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

Chapter 2. Asymptotic Notation

ORIE 633 Network Flows September 27, Lecture 8

Transcription:

Matrix Multiplicatio Data Structures ad Algorithms Adrei Bulatov

Algorithms Matrix Multiplicatio 7- Matrix Multiplicatio Matrix multiplicatio. Give two -by- matrices A ad B, compute A B. k kj ik ij b a c Brute force. arithmetic operatios. Fudametal questio. a we improve upo brute force? b b b b b b b b b a a a a a a a a a c c c c c c c c c L M O M M L L L M O M M L L L M O M M L L ( 3 ) Θ

Algorithms Matrix Multiplicatio 7-3 Matrix Multiplicatio: Divide ad oquer Divide: partitio A ad B ito ½-by-½ blocks. oquer: multiply 8 ½-by-½ recursively. ombie: add appropriate products usig 4 matrix additios. A A B B A B A B ( A B ) + ( A B) ( A B ) + ( A B ) ( A B ) + ( A B) ( A B ) + ( A B ) T( ) 3 ( / ) + Θ( ) T( ) Θ( ) 8T 443 recursive calls 3 add, form submatrices

Algorithms Matrix Multiplicatio 7-4 Better Divide ad oquer Key idea: multiply -by- block matrices with oly 7 multiplicatios. A A A A B B B B 3 4 5 6 7 A ( A ( A A ( A ( A ( A ( B ( B + A + A + A A A B ) B ) B B ) ( B ) ( B ) ( B ) ) + + + B B B ) ) ) 5 3 5 + 4 + + + 4 3 + 7 6

Algorithms Matrix Multiplicatio 7-5 Fast Matrix Multiplicatio Fast matrix multiplicatio. (Strasse, 969) Divide: partitio A ad B ito ½-by-½ blocks. ompute: 4 ½-by-½ matrices via 0 matrix additios. oquer: multiply 7 ½-by-½ matrices recursively. ombie: 7 products ito 4 terms usig 8 matrix additios. Aalysis. Assume is a power of. T() # arithmetic operatios. ( / ) T( ) 7T + Θ( ) T( ) Θ( ) O( 443 3 recursive calls add, subtract log 7.8 )

Algorithms Matrix Multiplicatio 7-6 Matrix Multiplicatio: ractice Implemetatio issues. Sparsity. achig effects. Numerical stability. Odd matrix dimesios. rossover to classical algorithm aroud 8. ommo misperceptio: "Strasse is oly a theoretical curiosity." Advaced omputatio Group at Apple omputer reports 8x speedup o G4 Velocity Egie whe ~,500. Rage of istaces where it's useful is a subject of cotroversy. Remark. a "Strasseize" Axb, determiat, eigevalues, ad other matrix operatios.

Algorithms Matrix Multiplicatio 7-7 Matrix Multiplicatio: Theory Q. Multiply two -by- matrices with oly 7 scalar multiplicatios? log 7 A. Yes! [Strasse, 969] Θ( ) O( Q. Multiply two -by- matrices with oly 6 scalar multiplicatios? log 6 A. Impossible. [Hopcroft ad Kerr, 97] Θ( ) O( Q. Two 3-by-3 matrices with oly scalar multiplicatios? log A. Also impossible. Θ( 3 ) O( Q. Two 70-by-70 matrices with oly 43,640 scalar multiplicatios? A. Yes! [a, 980] Decimal wars. December, 979: O(.583 ). Jauary, 980: O(.580 ). log 70 43640 Θ( ) O(.8.59.77.80 ) ) ) )

Algorithms Matrix Multiplicatio 7-8 Matrix Multiplicatio: Theory (ctd) Best kow. O(.376 ) [oppersmith-wiograd, 987.] ojecture. O( +ε ) for ay ε > 0. aveat: Theoretical improvemets to Strasse are progressively less practical.

Dyamic rogrammig Data Structures ad Algorithms Adrei Bulatov

Algorithms Dyamic rogrammig 7-0 Algorithmic aradigms Greed. Build up a solutio icremetally, myopically optimizig some local criterio. Divide-ad-coquer. Break up a problem ito two sub-problems, solve each sub-problem idepedetly, ad combie solutio to sub-problems to form solutio to origial problem. Dyamic programmig. Break up a problem ito a series of overlappig sub-problems, ad build up solutios to larger ad larger sub-problems.

Algorithms Dyamic rogrammig 7- Algorithmic aradigms Bellma. ioeered the systematic study of dyamic programmig i the 950s. Etymology. Dyamic programmig plaig over time. Secretary of Defese was hostile to mathematical research. Bellma sought a impressive ame to avoid cofrotatio. - "it's impossible to use dyamic i a pejorative sese" - "somethig ot eve a ogressma could object to"

Algorithms Dyamic rogrammig 7- Algorithmic aradigms Bellma. ioeered the systematic study of dyamic programmig i the 950s. Etymology. Dyamic programmig plaig over time. Secretary of Defese was hostile to mathematical research. Bellma sought a impressive ame to avoid cofrotatio. - "it's impossible to use dyamic i a pejorative sese" - "somethig ot eve a ogressma could object to"

Algorithms Dyamic rogrammig 7-3 Weighted Iterval Schedulig Weighted iterval schedulig problem. Istace A set of jobs. Job j starts at s j, fiishes at f j, ad has weight or value v j. Two jobs compatible if they do't overlap. Objective Fid maximum weight subset of mutually compatible jobs.

Algorithms Dyamic rogrammig 7-4 Uweighted Iterval Schedulig: Review Recall: Greedy algorithm works if all weights are. osider jobs i ascedig order of fiish time. Add job to subset if it is compatible with previously chose jobs. Observatio. Greedy algorithm ca fail spectacularly if arbitrary weights are allowed. weight 999 weight a b 0 3 4 5 6 7 8 9 0 Time

Algorithms Dyamic rogrammig 7-5 Weighted Iterval Schedulig Notatio: Label jobs by fiishig time: f f... f. Let p(j) be the largest idex i < j such that job i is compatible with j. Example. p(8) 5, p(7) 3, p() 0. 3 4 5 6 7 0 3 4 5 6 7 8 9 0 8 Time

Algorithms Dyamic rogrammig 7-6 Dyamic rogrammig: Biary hoice Let OT(j) deote the value of a optimal solutio to the problem cosistig of job requests,,..., j. ase : OT selects job j. caot use icompatible jobs { p(j) +, p(j) +,..., j - } must iclude optimal solutio to problem cosistig of remaiig compatible jobs,,..., p(j) ase : OT does ot select job j. optimal substructure must iclude optimal solutio to problem cosistig of remaiig compatible jobs,,..., j- OT ( j) 0 max { v + OT ( p( j)), OT ( j ) } j if j 0 otherwise

Algorithms Dyamic rogrammig 7-7 Weighted Iterval Schedulig: Brute Force Iput:, s,,s, f,,f, v,,v sort jobs by fiish times so that f f f compute p(), p(),, p() retur ompute-opt() ompute-opt(j) if (j 0) retur 0 else retur max(v j +ompute-opt(p(j)),ompute-opt(j-))

Algorithms Dyamic rogrammig 7-8 Weighted Iterval Schedulig: Brute Force Observatio. Recursive algorithm fails spectacularly because of redudat sub-problems expoetial algorithms. Example Number of recursive calls for family of "layered" istaces grows like Fiboacci sequece. 5 3 4 5 4 3 3 0 0 p() 0, p(j) j - 0

Algorithms Dyamic rogrammig 7-9 Weighted Iterval Schedulig: Memoizatio Memoizatio: Store results of each sub-problem i a cache; lookup as eeded. Iput:, s,,s, f,,f, v,,v sort jobs by fiish times so that f f f compute p(), p(),, p() set OT[0]:0 for j to do set OT[j]:max(v j +OT[p(j)],OT[j-]) edfor retur OT[]

Algorithms Dyamic rogrammig 7-0 Weighted Iterval Schedulig: Ruig Time Theorem Memoized versio of algorithm takes O( log ) time. roof Sort by fiish time: O( log ). omputig p( ) : O() after sortig by fiish time Each iteratio of the for loop: O() Overall time is O( log ) Remark. O() if jobs are pre-sorted by fiish times QED

Algorithms Dyamic rogrammig 7- Automated Memoizatio Automated memoizatio. May fuctioal programmig laguages (e.g., Lisp) have built-i support for memoizatio. Q. Why ot i imperative laguages (e.g., Java)? (defu F () (if (< ) (+ (F (- )) (F (- ))))) Lisp (efficiet) static it F(it ) { if ( < ) retur ; else retur F(-) + F(-); } Java (expoetial) F(40) F(39) F(38) F(38) F(37) F(37) F(36) F(37) F(36) F(36) F(35) F(36) F(35) F(35) F(34)

Algorithms Dyamic rogrammig 7- Fidig a Solutio Dyamic programmig algorithm computes optimal value. What if we wat the solutio itself? Do some post-processig Fid-Solutio(j) if j 0 the output othig else if v j +M[p(j)]>M[j-] the do prit j Fid-Solutio(p(j)) edif else Fid-Solutio(j-) edif