0% found this document useful (0 votes)
9 views

S17-18_Dynamic Programming

Uploaded by

Asmita
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

S17-18_Dynamic Programming

Uploaded by

Asmita
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Dynamic Programming

Session 17-18
Introduction
• Efficient way of searching solution space efficiently.
• Efficiency is achieved via dividing problem into subproblem and using
its solution in other problem
Ex. Fibonachy series
int fib(int n)
{
if (n<=1)
return n;
return fib(n-2) +fib (n-1)
}
General Characteristics of Problems Not
Suited for Subproblems:
• No useful smaller instances: Sometimes breaking a problem into smaller
instances won’t help because those smaller instances don't provide any insight into
the bigger problem (e.g., sorting randomly ordered elements).

• Highly interdependent choices: Decisions in one part of the problem may


drastically change the rest of the problem. (Rare)
Checklist for Identifying Overlapping
Subproblems:
 Recursive Nature/ Redundant Computation
 Shared State
(Different parts of the problem share some common information or state)
 Sequential Decision Making
12
2
5
7 9
Shortest Path Problem 8
8 7
1 3 9
6
6
7
5
13
4

Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4
Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4

fi  min{d  f i 1}
S
Optimal Solution at Optimal Solution at
stage i stage i-1
Solution Space
at stage i Distance
covered
Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4

f 2 (2,5)  12  7  19
f1 (1, 2)  7 f 2 (3,5)  8  8  16
f1 (1,3)  8 f 2 (4,5)  7  5  12
f1 (1, 4)  5
Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4

f 2 (2,5)  12  7  19
f1 (1, 2)  7 f 2 (3,5)  8  8  16
f1 (1,3)  8 f 2 (4,5)  7  5  12
f1 (1, 4)  5
f 2 (3, 6)  9  8  17
f 2 (4, 6)  13  5  18
Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4

f 2 (2,5)  12  7  19
f1 (1, 2)  7 f 2 (3,5)  8  8  16
f1 (1,3)  8 f 2 (4,5)  7  5  12
f1 (1, 4)  5
f 2 (3, 6)  9  8  17
f 2 (4, 6)  13  5  18
Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4

f 2 (2,5)  12  7  19 f3 (5, 7)  9  12  21
f1 (1, 2)  7 f 2 (3,5)  8  8  16 f3 (6, 7)  6  17  23
f1 (1,3)  8 f 2 (4,5)  7  5  12
f1 (1, 4)  5
f 2 (3, 6)  9  8  17
f 2 (4, 6)  13  5  18
Stage 1 Stage 2 Stage 3

2 12
2
5 5
7 9
8
8 7
1 3 3 9
6 6
6
5 7
4 13
4

f 2 (2,5)  12  7  19 f3 (5, 7)  9  12  21
f1 (1, 2)  7 f 2 (3,5)  8  8  16 f3 (6, 7)  6  17  23
f1 (1,3)  8 f 2 (4,5)  7  5  12
f1 (1, 4)  5
f 2 (3, 6)  9  8  17
f 2 (4, 6)  13  5  18
Summary of Steps
1. Definition of Stages
2. Definition of alternatives at each stage
3. Definition of the states for each stage

• Both forward and backward recursions yield the same solution


• In general, backward recursion may be more efficient computationally

You might also like