Chained Matrix Multiplication and Recursion - PowerPoint PPT Presentation

About This Presentation
Title:

Chained Matrix Multiplication and Recursion

Description:

Chained Matrix Multiplication. and Recursion. Lecture 16. CS 312. Project 2. Times are strange ... I like graphs more than tables for quantitative information ... – PowerPoint PPT presentation

Number of Views:116
Avg rating:3.0/5.0
Slides: 15
Provided by: mike437
Category:

less

Transcript and Presenter's Notes

Title: Chained Matrix Multiplication and Recursion


1
Chained Matrix Multiplicationand Recursion
  • Lecture 16
  • CS 312

2
Project 2
  • Times are strange
  • lt30sec , lt40sec, lt50sec, lt60sec, gt60sec
  • Sample data sets and solutions available

3
Resources
  • Writing For Computer Science by Justin Zobel
  • The Visual Display of Quantitative Information
    by Edward R. Tufte
  • Writing center 1010 JKHB, 8-4306

4
Project 1
  • Experiments were, in general, very interesting
  • Do not narrate "First, I did ... Then I did ....
    Then I did ... "
  • I like graphs more than tables for quantitative
    information
  • Follow the guidelines on the webpage
  • dbl space, cover sheet
  • Section headings dont hurt
  • Lengths were good

5
Project 3
  • Dont start project 3 yet. It might change

6
Objective
  • Optimize chained matrix mult. using DP (bottom-up
    first, then top-down)
  • Rewrite bottom-up DP algorithms as top-down
    algorithms using a table

7
Bottom-up matrix mult.
for s 0 to n - 1 if s 0 then for i 1 to
n mi,i 0 else if s 1 then for i 1
to n-1 mi,i1 di-1 di di1 else
for i 1 to n - s mi,is infinity
for k i to i s mi,is min
(mi,is, mi,k mk1,is di-1 dk
dis) mi,is sofar
8
Bottom-up vs. Top-down
  • Might compute irrelevant subsolutions
  • Manage recursion

9
Top-down Recursive Approach
function fm (i,j) if i j then return 0 m
infinity for k 1 to j - 1 do m min (m ,
fm(i,k)fm(k1,j) di-1dkdj return m
Whats the complexity of this algorithm?
10
Call Tree
fm(1,4)
fm(1,1) fm(2,4)
fm(1,2) fm(3,4)
fm(1,3) fm(4,4)
fm (2,2) fm(3,4)
fm(1,1) fm(2,2)
fm(3,3) fm(4,4)
fm(1,1) fm(2,3)
fm(1,2) fm(3,3)
fm (2,3) fm(4,4)
fm(3,3) fm(4,4)
fm(2,2) fm(3,3)
fm(2,2) fm(3,3)
fm(1,1) fm(2,2)
11
Call Tree
fm(1,4)
fm(1,1) fm(2,4)
fm(1,2) fm(3,4)
fm(1,3) fm(4,4)
fm (2,2) fm(3,4)
fm(1,1) fm(2,2)
fm(3,3) fm(4,4)
fm(1,1) fm(2,3)
fm(1,2) fm(3,3)
fm (2,3) fm(4,4)
fm(3,3) fm(4,4)
fm(2,2) fm(3,3)
fm(2,2) fm(3,3)
fm(1,1) fm(2,2)
How do you modify fm to avoid recomputing results?
12
Memory Function
function fm-mem (i,j) if i j then return 0 if
mtab i,j gt -1 then return mtabi,j m
infinity for k 1 to j - 1 do m min (m ,
fm-mem(i,k)fm-mem(k1,j) di-1dkdj
mtabi,j m return m
13
Call Tree
fm(1,4)
fm(1,1) fm(2,4)
fm(1,2) fm(3,4)
fm(1,3) fm(4,4)
fm (2,2) fm(3,4)
fm(1,1) fm(2,2)
fm(3,3) fm(4,4)
fm(1,1) fm(2,3)
fm(1,2) fm(3,3)
fm (2,3) fm(4,4)
fm(3,3) fm(4,4)
fm(2,2) fm(3,3)
fm(2,2) fm(3,3)
fm(1,1) fm(2,2)
14
Homework
  • Problem 8.27. Replace and with or
  • knapsack is the project though.
  • Fill in the table using a memory function
Write a Comment
User Comments (0)
About PowerShow.com