
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Kowalczyk; Class: Algorithms Design And Analysis; Subject: Computer Science; University: Northern Michigan University; Term: Winter 2008;
Typology: Study notes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Algorithm Design and Analysis 3/16/
Instructor: Mike Kowalczyk
How efficient is matrix multiplication? That is, if we have two n × n matrices, how many multiplications and additions do we need carry out to multiply those matrices? If we have some particular row and column that we want to multiply together, that will take n multiplications (and n − 1 additions). This gives us the answer for just one entry in the resulting matrix. But we need n^2 answers, so the total is n^3 multiplications, and n^3 − n^2 additions. There are more efficient ways of multiplying matrices. For example, a cleverly designed divide-and-conquer technique can get o(n^3 ) multiplications, but today we will just use the straightforward way of multiplying matrices. How many multiplications does it take when we have a p × q matrix times a q × r matrix? A little thought shows that the total number of multiplications is pqr, by a similar argument to what we saw above. Now consider a problem like this:
When you multiply a p × q matrix by a q × r matrix, you get a p × r matrix. We could do this 3-matrix problem by multiplying the left two first or the right two first. Which one is better? If we do the right two mutliplied first, then we get 2 · 4 · 1 + 3 · 2 · 1 = 14 multiplications. The other way, we get 3 · 2 · 4 + 3 · 4 · 1 = 36 multiplications. Much worse! So apparently, it makes a big difference which matrix multiplications you do first. Given a big chain of matrices, figuring out the most efficient way to multiply them together in this way (which order to do first) is called matrix parenthesization. Can we use dynamic programming to solve this problem in Θ(nk) steps for some constant k, thereby proving that the matrix parenthesization problem is in the complexity class P? We can multiply pairs of matrices together and build a table to keep track of how many mul- tiplications it took to get to that point. At each level we could use an array keep track of these different values. With the different possibilities for one level in hand, we can figure out the optimal number of multiplications for each node in the next level. But how is this table organized? What does each entry represent? How are we convinced that this works? Can we write pseudocode for this algorithm? What is the runtime?