Download presentation

Presentation is loading. Please wait.

Published byDanna Grandin Modified about 1 year ago

1
Algorithm Design Methodologies Divide & Conquer Dynamic Programming Backtracking

2
Optimization Problems Dynamic programming is typically applied to optimization problems In such problems, there are many feasible solutions We wish to find a solution with the optimal (maximum or minimum value) Examples: Minimum spanning tree, shortest paths

3
Matrix Chain Multiplication To multiply two matrices A (p by q) and B (q by r) produces a matrix of dimensions (p by r) and takes p * q * r “simple” scalar multiplications

4
Matrix Chain Multiplication Given a chain of matrices to multiply: A1 * A2 * A3 * A4 we must decide how we will paranthesize the matrix chain: –(A1*A2)*(A3*A4) –A1 * (A2 * (A3*A4)) –A1 * ((A2*A3) * A4) –(A1 * (A2*A3)) * A4 –((A1*A2) * A3) * A4

5
Matrix Chain Multiplication We define m[i,j] as the minimum number of scalar multiplications needed to compute A i..j Thus, the cheapest cost of multiplying the entire chain of n matrices is A [1,n] If i <> j, we know m[i,j] = m[i,k] + m[k+1,j] + p[i-1]*p[k]*p[j] for some value of k [i,j)

6
Elements of Dynamic Programming Optimal Substructure Overlapping Subproblems

7
Optimal Substructure This means the optimal solution for a problem contains within it optimal solutions for subproblems. For example, if the optimal solution for the chain A1*A2*…*A6 is ((A1*(A2*A3))*A4)*(A5*A6) then this implies the optimal solution for the subchain A1*A2*….*A4 is ((A1*(A2*A3))*A4)

8
Overlapping Subproblems Dynamic programming is appropriate when a recursive solution would revisit the same subproblems over and over In contrast, a divide and conquer solution is appropriate when new subproblems are produced at each recurrence

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google