Download presentation
Presentation is loading. Please wait.
1
Dynamic Programming 2 Neil Tang 4/22/2010
CS223 Advanced Data Structures and Algorithms
2
CS223 Advanced Data Structures and Algorithms
Course Survey Please complete the course survey at: CS223 Advanced Data Structures and Algorithms
3
CS223 Advanced Data Structures and Algorithms
Class Overview Basic idea Matrix multiplication Ordering matrix multiplication CS223 Advanced Data Structures and Algorithms
4
CS223 Advanced Data Structures and Algorithms
Basic Idea Mathematically express the problem in the recursive form. Solve it by a non-recursive algorithm that systematically records the answers to the subproblems in a table. CS223 Advanced Data Structures and Algorithms
5
Matrix Multiplication
C=AB. If the size of A is wy, then the size of B must be yz, i.e., the number of columns of A must be equal to the number of rows of B. The size of C is wz and CS223 Advanced Data Structures and Algorithms
6
CS223 Advanced Data Structures and Algorithms
An Example Compute ABCD with |A|=5010, |B| = 1040, |C|=4030 and |D|=305. (((AB)C)D) involves 20,000+60,000+7,500 =87,500 multiplications. (A((BC)D)) involves 12,000+1,500+2,500 =16,000 multiplications. (A(B(CD))) involves 6,000+2,000+2,500 =10,500 multiplications. CS223 Advanced Data Structures and Algorithms
7
Ordering Matrix Multiplications
Consider AleftAleft+1…Ai…Aright mleft,right = min leftiright {mleft,i + mi+1,right+cleft-1cicright} CS223 Advanced Data Structures and Algorithms
8
CS223 Advanced Data Structures and Algorithms
Another Example right left right left CS223 Advanced Data Structures and Algorithms
9
Ordering Matrix Multiplications
The time complexity is O(n3) CS223 Advanced Data Structures and Algorithms
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.