1
2/16/06 CS 3343 Analysis of Algorithms 1
CS 3343 -- Spring 2006
Matrix Multiplication
Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk
2/16/06 CS 3343 Analysis of Algorithms 2
Powering a number
Problem: Compute a n, where n ∈ N. a n = a n/2 ⋅ a n/2 if n is even; a (n–1)/2 ⋅ a (n–1)/2 ⋅ a if n is odd. Divide-and-conquer algorithm: (recursive squaring) T(n) = T(n/2) + Θ(1) ⇒ T(n) = Θ(logn) . Naive algorithm: Θ(n).
(a bit easier than the recursive mystery question on the homework)
2/16/06 CS 3343 Analysis of Algorithms 3
Matrix multiplication
⋅ =
nn n n n n nn n n n n nn n n n n
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
2 1 2 22 21 1 12 11 2 1 2 22 21 1 12 11 2 1 2 22 21 1 12 11
∑
=
⋅ =
n k kj ik ij
b a c
1
Input: A = [aij], B = [bij]. Output: C = [cij] = A⋅ B. i, j = 1, 2,… , n.
2/16/06 CS 3343 Analysis of Algorithms 4