cs209 lab8


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l8.html




This lab is based on the dynamic programming solution to the matrix multiplication problem covered in lectures. You can use as a starting point the program matrix.py handed out at lectures or available at http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/. For other reading on this problem, there are many good sources on the internet, for example:

  1. http://en.wikipedia.org/wiki/Matrix_chain_multiplication
  2. http://www.seas.gwu.edu/~ayoussef/cs212/dynamicprog.html
  3. http://www.columbia.edu/~cs2035/courses/csor4231.F11/matrix-chain.pdf
  4. http://www.cs.sunysb.edu/~jgao/CSE548-fall07/David-mount-DP.pdf
For this week, you should modify the matrix.py program so that
  1. It is "nicer": i.e., it has comments, variable/function names are well chosen, it reads the matrix dimensions in from the user and prints out the resulting optimum no. of multiplications. (Also - come up with some other systematic way of replacing the large number MAX by some other large number (dependent on the list of matrix dimensions) that is guaranteed to be large enough.)
  2. As well as calculating the fewest no. of multiplications, it also calculates the worst case (largest no. of multiplications). You should report the difference as a percentage (example: if the best case used 555 multiplications, and the worst case used 2220, then report "the number of products used in the best case is 25% of those used in the worst case").
Run your program on the matrix dimensions:
  1. [10,110,15,50,1]
  2. [40,20,30,72,30,70,2,95,45,30,26,7,87]
  3. [3,28,4,21,5,2,6,21,7,24,3]
and submit these three answers.

© NUI, Galway