Académique Documents
Professionnel Documents
Culture Documents
Inhalt
1
Introduction ...................................................................................................................... 1
2
Basic Concept about dynamic programmingError!
defined.
Bookmark
not
3
3.1
3.2
3.3
4
Dynamic Programming...............................................................7
Conclusion .............................................................................9
References ....................................................................................................................... 10
- i-
1 Introduction
Dynamic programming is a method for solving difficult problem by breaking it down into
similar smaller problems. To solve a given problem by using dynamic programming need to
divide the problem, solve the different parts and combine the solution. Dynamic programming
overcome the overlapping problem, time consuming problem for shortest path calculation
between two points. Its practical application is huge. It introduces some new techniques such
as memorization, subdivision which have big impact on algorithm design, programming and
many more complex problems. Dynamic programming was introduced by Richard Bellman in
1940 for finding the best solution one after one. Now every programmer, designer considers
this as a technique for problem solution.1
(Wikipedia)
(MIT)
Fn
According the picture, there is two times of Fn-3. If we use Naive Recursive algorithm
then need to calculate two times the same things. It is wastage of time. If we use Dynamic
Programming then dont need to calculate the same thing again because it is already in
memory, so just need to call the result. 2
- 2-
1 2
2
6
5
3
7
1
4
3
3
4
11
10
12
2
8
11
8
11
According to the figure there are 5 stages and 12 nodes. We will calculate the shortest
path from node 1 to node 12 by using greedy algorithm, brute force and dynamic
programming. From node 1 to node 2 weight is 9, Node 1 to 3, 4, 5 weights are 7, 3, and 2
respectively. Node 1 stands on stage one, node 2,3,4,5 on stage two, node 6, 7, 8 on stage
three, node 9,10,11 on stage four and the last stage is node 12 on stage five.3
(Shortest path)
- 3-
1 2
2
6
5
9
4
3
7
1
4
3
7
4
11
2
8
12
11
5
10
11
According to the greedy choice from stage 1 to stage 2 we have to select shortest edge.
From stage one to stage two the shortest path is 2 then stage two to three is 8, three to four is
5 and four to 5 is 2. The total weight is 17.
- 4-
1 2
2
6
5
3
7
1
4
3
3
4
11
10
12
2
8
11
8
11
According to the figure 4, shows totally opposite of the greedy algorithm. From stage
one to stage two it visited the biggest edge, the weight is 9. This is totally opposite the greedy
algorithm. Then stage two to stage three weight is 2 , stage three to four weight is 3 and
finally stage four to stage five weight is 2. Total weight is 16. It is opposite the greedy
algorithm but it shows the shortest path. So, greedy algorithm fails here.
- 5-
6
7
7
8
10
9
10 10
11 9 10 9
10
10 11
10
10 11
- 6-
1 2
2
6
5
3
7
1
4
3
3
4
11
10
12
2
8
11
8
11
- 7-
7
9
6
3
5
10
12
4
8
11
7
5
Second Stage:
Cost (2, 2) = min (4+7, 2+5, 1+7) = 7
Cost (2, 3) = min (2+7, 7+5) = 9
Cost (2, 4) = min (11+7) = 18
Cost (2, 5) = min (11+5, 11+7) = 16
7
2
9
10
11
3
18
12
4
16
5
Figure: Second stage minimum path
- 8-
First Stage:
Cost (1, 1) = min (9+7, 7+9, 3+18, 2+16) = 16
7
2
9
9
10
11
7
1
18
12
4
2
16
5
The shortest path is 16. We solved this problem by backward method. There are no
overlapping and unnecessary delays. We found two shortest path in our multistage graph.
Every stage we calculated one time and saved the result in the memory. So, next time
when we need the result then we called it.
Conclusion:
Finally, we can say that dynamic programming is very effective to solve any problem.
To design anything we should always consider the time and cost. Dynamic programming
concept can give that solution.
- 9-
References
1.
2.
3.
4.
Wikipedia: http://en.wikipedia.org/wiki/Dynamic_programming#History
MIT:https://www.youtube.com/watch?v=OQ5jsbhAv_M
Shortest path: https://www.youtube.com/watch?v=m5Y-4TsXsJ0
https://www.youtube.com/watch?v=WN3Rb9wVYDY
- 10 -