Regd.No: Page No: Class: II IT II SEM DESIGN & ANAL YSIS OF ALGORITHMS PROGRAM-7 DATE: Matrix chain multiplication by using dynamic programming method. Suppose e ha!e a se"uence or chain #$% #&% '% #n o( n matrices to be multiplied ) That is% e ant to comput e the product #$#&'#n There are many possible ays *parenthesi+ations, to compute the product Example: consider the chain #$% #&% #-% #o( matrices ) /et us compute the product # $#&#-#There are 0 possible ays: ) *#$*#&*#-#,,, ) *#$**#&#-,#,, ) **#$#&,*#-#,, ) **#$*#&#-,,#, ) ***#$#&,#-,#, Example: Consider three matrices #$12$11% 3$1120% and C0201 There are & ays to parenthesi+e ) **#3,C, 4 5$120 6 C0201 6 #3 7 $16$116040%111 scalar multipl ications 6 5C 7 $160601 4&%011 scalar multipl ications 6 Total: 8%011 ) *#*3C,, 4 #$12$11 6 E$11201 6 3C 7 $11606014&0%111 scalar multiplications 6 #E 7 $16$1160 1 401%111 scalar mul ti pl icati ons 6 Total: 80%111 The structure o( an optimal solution /et us use the notation #i..9 (or the matrix that results (rom the product #i #i$ ' #9 #n optimal parenthesi+ation o( the product #$#&'# n splits the product beteen #; and # ;$ (or some inte ger ; here$ < ; = n. >irst compute matrices #$..; and #;$..n ? then multiply them to get the (inal matrix #$..n @IAN#NBS >DN5#TIN >R SCIENCE%TECN/AF #N5 RESE#RC
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.