This presentation on 'What Is Dynamic Programming?' will acquaint you with a clear understanding of how this programming paradigm works with the help of a real-life example. In this Dynamic Programming Tutorial, you will understand why recursion is not compatible and how you can solve the problems involved in recursion using DP. Finally, we will cover the dynamic programming implementation of the Fibonacci series program. So, let's get started!
The topics covered in this presentation are:
1. Introduction
2. Real-Life Example of Dynamic Programming
3. Introduction to Dynamic Programming
4. Dynamic Programming Interpretation of Fibonacci Series Program
5. How Does Dynamic Programming Work?
What Is Dynamic Programming?
In computer science, something is said to be efficient if it is quick and uses minimal memory. By storing the solutions to subproblems, we can quickly look them up if the same problem arises again. Because there is no need to recompute the solution, this saves a significant amount of calculation time. But hold on! Efficiency comprises both time and space difficulty. But, why does it matter if we reduce the time required to solve the problem only to increase the space required? This is why it is critical to realize that the ultimate goal of Dynamic Programming is to obtain considerably quicker calculation time at the price of a minor increase in space utilized. Dynamic programming is defined as an algorithmic paradigm that solves a given complex problem by breaking it into several sub-problems and storing the results of those sub-problems to avoid the computation of the same sub-problem over and over again.
What is Programming?
Programming is an act of designing, developing, deploying an executlable software solution to the given user-defined problem.
Programming involves the following stages.
- Problem Statement
- Algorithms and Flowcharts
- Coding the program
- Debug the program.
- Documention
- Maintainence
Simplilearn’s Python Training Course is an all-inclusive program that will introduce you to the Python development language and expose you to the essentials of object-oriented programming, web development with Django and game development. Python has surpassed Java as the top language used to introduce U.S.
Learn more at: https://www.simplilearn.com/mobile-and-software-development/python-development-training
What Is Dynamic Programming? | Dynamic Programming Explained | Programming For Beginners|Simplilearn
1.
2. What’s in It For You?
Real-Life Example of Dynamic
Programming
Introduction to Dynamic
Programming
How Does Dynamic Programming Work?
Dynamic Programming Interpretation of
Fibonacci Series Program
7. Rachael began playing this game with her friend Alex, who was
already familiar with it.
8. While playing with Alex, Rachael kept losing the game. As a
result, she got frustrated!
9. After losing a few games, Rachael began to recall the outcomes of each of her
moves, which led her towards failure. Now she began playing Tic-tac-toe
intelligently, keeping those moves in mind.
10. Rachael used her memory to recall the results of her prior decisions. As a result of her
commitment to learn from her past, she went on a winning streak against Alex.
11. The notion behind the dynamic programming paradigm is that those who do not remember the
past are condemned to repeat it.
12. If we can handle and remember smaller problems, their learnings can be memorized to
solve the bigger problems. This general principle is considered as a building block of
dynamic programming.
14. Dynamic programming is an algorithmic paradigm for
solving a given complex problem by breaking it down
into subproblems and memorizing the outcomes of
those subproblems to prevent repeating
computations.
Dynamic programming can only be applied to the given
problem if it follows the properties of dynamic
programming.
What Is Dynamic Programming?
15. Properties of Dynamic Programming
A problem is said to have an optimal substructure if we can formulate a
recurrence relation for it.
1. Optimal Substructure
Consider the coin change problem, in which you have to construct coin combinations with
the least potential number of coins.
50$ coin 20$ coin 10$ coin 5$ coin
16. Properties of Dynamic Programming
A problem is said to have an overlapping subproblem if the subproblems reoccur
when implementing a solution to the larger problem.
2. Overlapping Subproblem
Overlapping Subproblem can be understood by developing recurrence relationships.
For example, Fibonacci Series.
𝒇𝒊𝒃 𝒏 = 𝒇𝒊𝒃 𝒏 − 𝟏 + 𝒇𝒊𝒃(𝒏 − 𝟐)
17. What Should We Cover Next?
What Dynamic Programming
problems would you like us to
cover in our upcoming videos?
19. Fibonacci Series
Fibonacci series is the set of numbers which appear in nature all the time. Each
number in this series is equal to the sum of previous numbers before it.
𝒇𝒊𝒃(𝒏) = 𝒇𝒊𝒃(𝒏 − 𝟏) + 𝒇𝒊𝒃(𝒏 − 𝟐)
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, .....
When n <=1
Fib(0) = 0
Fib(1) = 1
Otherwise
20. Fibonacci Series
Fibonacci series is the set of numbers which appear in nature all the time. Each
number in this series is equal to the sum of previous numbers before it.
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, .....
n 0 1 2 3 4 5
Fib(n) 0 1 1 2 3 5
21. Optimal Substructure: Fibonacci Series
If we can establish a recurrence relation for a problem, we say it has
an optimal substructure.
int Fib(int z)
{
if(z<=1){
return z;
}
else{
return Fib(n-1) +
Fib(n-2);
}
}
𝒇𝒊𝒃 𝒏 = 𝒇𝒊𝒃 𝒏 − 𝟏 + 𝒇𝒊𝒃(𝒏 − 𝟐)
Recurring Relation
22. Overlapping Subproblem: Fibonacci Series
If the subproblems recur while implementing a solution to the bigger
problem, the problem is said to have an overlapping subproblem.
Let’s say we want to calculate Fibonacci numbers for n = 5.
28. How Does Dynamic Programming Work?
Solution: Utilize Memory
Remember the result for each Sub-Problem.
Solving a Subproblem Memory Area
29. How Does Dynamic Programming Work?
Solution: Utilize Memory
Remember the result for each Sub-Problem.
Memory Area Recurred Subproblem
30. How Does Dynamic Programming Work?
Dynamic programming stores the results of subproblems in memory and
recalls it whenever the recurrence of calculated subproblem occurs.
Two methods of storing the results in memory.
Memorization: In this method, we store the results in memory whenever
we solve a particular subproblem for first time.
Tabulation: In this method, we precompute the solutions in a linear
fashion and store it in a tabular format.
31. Ways to Handle
Overlapping
Subproblems
Memorization Tabulation
Also called as Top-Down
Approach
A Lookup table is maintained and
checked before computation of
any state
Recursion is involved
Also called as Bottom-Up
Approach
In this method, the solution is built
from the base or bottom-most
state
This process is iterative
32. Overlapping handling
for Fibonacci Series
Program
Memorization Tabulation
int fib(int n)
{
if(n<=1){
return n;
}
if(fib(n) != -1)
return fib(n);
int res = fib(n-1) + fib(n-2);
fib(n) = res;
return res;
}
int fib(int n)
{
int t[n+1];
int i;
t[0] = 0;
t[1] = 1;
for(i=2; i <= n; i++)
{
t(i) = t(i-1) + t(i-2);
}
return t(n);
}
Memorization
Tabulation
33. When to Use Dynamic Programming?
1. When we need an exhaustive solution, we can use Dynamic
programming to address minimization and maximization problems.
2. Permutation problems: find the number of ways problems can be
solved using DP.