Docsity

Dynamic Programming For Solving Optimization Problems-Advance Analysis Design-Lecture Slides, Slides of Design and Analysis of Algorithms

Partial preview of the text

Download Dynamic Programming For Solving Optimization Problems-Advance Analysis Design-Lecture Slides and more Slides Design and Analysis of Algorithms in PDF only on Docsity!

Lecture No. 15

Dynamic Programming for Solving

Optimization Problems

(Chain Matrix Multiplication Problem)

•^

Optimizations problem?

-^

Steps in Development of Dynamic Algorithms

-^

Why dynamic in optimization problem?

-^

Introduction to Catalan numbers

-^

Chain-Matrix Multiplication

-^

Problem Analysis– Brute Force approach– Time Complexity

-^

Conclusion

Today Covered

Characterize the structure of an optimal solution

Recursively define the value of an optimalsolution

Compute the value of an optimal solution in abottom-up fashion

Construct an optimal solution from computedinformationNote: Steps 1-3 form the basis of a dynamicprogramming solution to a problem. Step 4 canbe omitted only if the value of an optimalsolution is required.

Steps in Development of Dynamic Algorithms

•^

Dynamic programming, like divide and conquermethod, solves problems by combining thesolutions to sub-problems.

-^

Divide and conquer algorithms:• partition the problem into independent sub-problem• Solve the sub-problem recursively and• Combine their solutions to solve the original problem

-^

In contrast, dynamic programming is applicablewhen the sub-problems are not independent.

-^

Dynamic programming is typically applied tooptimization problems.

Why Dynamic Programming?

Catalan Numbers

Objective:•^

Find C(n), the numberof ways to computeproduct x

1

. x

2

…. x

.n^

n

multiplication order

(x

1

· x

(x

1

· (x

2

· x

((x

1

· x

) · x 2

(x

1

· (x

2

· (x

3

· x

(x

1

· ((x

2

· x

) · x 3

((x

1

· x

) · (x 2

3

· x

((x

1

· (x

2

· x

)) · x 3

(((x

1

· x

) · x 2

) · x 3

Multiplying n Numbers

Recursive equation:

where is the last multiplication?

(^

k n C k C

n k

n C

. (^21)

2 1 ) (^

 

 

 

^

n n

n

n C

(^2) / 4 3

) (^

n

n C

n

 

n for 4

1)- C(n)C(n

Catalan numbers:Asymptotic

value

:

Multiplying n Numbers - small n

Chain-Matrix Multiplication

•^

Given a sequence of matrices, we want to find amost efficient way to multiply these matrices

-^

It means that problem is not actually to perform themultiplications, but decide the order in which thesemust be multiplied to reduce the cost.

-^

This problem is an optimization type which can besolved using dynamic programming.

-^

The problem is not limited to find an efficient way ofmultiplication of matrices, but can be used to beapplied in various purposes.

-^

But how to transform the original problem into chainmatrix multiplication, this is another issue, which iscommon in systems modeling.

Objective is to find order not multiplication

•^

If these matrices are all square and of same size,the multiplication order will not affect the total cost.

-^

If matrices are of different sizes but compatible formultiplication, then order can make big difference.

-^

Brute Force approach– The number of possible multiplication orders are

exponential in n, and so trying all possible ordersmay take a very long time.

•^

Dynamic Programming– To find an optimal solution, we will discuss it

using dynamic programming to solve it efficiently.

Why this problem is of Optimization Category?

Chain Matrix Multiplication

(Brute Force Approach)

•^

If we wish to multiply two matrices:A = a[i, j]

p, q

and B = b[i, j]

q, r

•^

Now if C = AB then order of C is p x r.

-^

Since in each entry c[i, j], there are q number ofscalar of multiplications

-^

Total number of scalar multiplications incomputing C = Total entries in C x Cost ofcomputing a single entry = p. r. q

-^

Hence the computational cost of AB = p. q. r

Brute Force Chain Matrix Multiplication Algorithm

•^

There are five ways to parenthesize this product

-^

Cost of computing the matrix product may vary,depending on order of parenthesis.

-^

All possible ways of parenthesizing

(A

1

· (A

2

. (A

3

. A
(A

1

· ((A

2

. A
). A 3
((A

1

· A
). (A 2

3

. A
((A

1

· (A

2

. A
)). A 3
(((A

1

· A
). A 2
). A 3

Brute Force Chain Matrix Multiplication

Kinds of problems solved by algorithms