Professional Documents
Culture Documents
Design and Analysis Algorithm: Lecture Dynamic Programming
Design and Analysis Algorithm: Lecture Dynamic Programming
Lecture ( )
Dynamic Programming
Dynamic Programming definition
Two main properties of a problem suggest that the given problem can be solved
using Dynamic Programming. These properties are overlapping sub-problems and
optimal substructure.
The dynamic programming is working like this
Main problem
Then solved the first sub problem, take the result of first sub problem and solved the second sub
problem … etc. until solved all the problem
Main problem
0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , . . .
each number in Fibonacci series is the product of the addition of the two previous
numbers.
If we need to predict the new number in Fibonacci series then addition the two
previous number. the new number = 89+55 = 144
Dynamic programming complexity analysis
1. using recursive function
Fin ( int x ) E (T) = 0
{
if ( x = = 0 ) E (T) = N
return 0; E (T) = N-1
if ( x = = 1 ) E (T) = N
return fib( x-1 ) + fib ( x-2 ) E; (T) = N E (T) = N-1 E (T) = N-2
}
The result of time complexity = O(N) = n!
1. using Dynamic Programming strategy
In this strategy we divided the problem to small sub problem and solved the first sub problem, take
the result of first sub problem and solved the second sub problem … etc. until solved all the
problem
Fib[ ] E (T) = 0
Fib[ 0 ] = 0 ; E (T) = 1
Fib[ 1 ] = 1 ; E (T) = 1
For example, Binary Search does not have overlapping sub-problem. Whereas
recursive program of Fibonacci numbers have many overlapping sub-problems.
Steps of Dynamic Programming Approach