SlideShare a Scribd company logo
What Is Dynamic Programming? | Dynamic Programming Explained | Programming For Beginners|Simplilearn
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
Real-Life Example of Dynamic
Programming
Click here to watch the video
This is Rachael. She loves solving complex puzzles.
While searching through her puzzle book, she came across a
tic-tac-toe puzzle.
Rachael began playing this game with her friend Alex, who was
already familiar with it.
While playing with Alex, Rachael kept losing the game. As a
result, she got frustrated!
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.
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.
The notion behind the dynamic programming paradigm is that those who do not remember the
past are condemned to repeat it.
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.
Introduction to Dynamic
Programming
 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?
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
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.
𝒇𝒊𝒃 𝒏 = 𝒇𝒊𝒃 𝒏 − 𝟏 + 𝒇𝒊𝒃(𝒏 − 𝟐)
What Should We Cover Next?
What Dynamic Programming
problems would you like us to
cover in our upcoming videos?
Dynamic Programming Interpretation of
Fibonacci Series Program
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
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
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
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.
Fib(5)
Fib(4)
Fib(3)
Fib(2)
Fib(1) Fib(0)
Fib(1)
Fib(2)
Fib(1) Fib(0)
Fib(3)
Fib(2)
Fib(1) Fib(0)
Fib(1)
Let’s say we want to calculate Fibonacci numbers for n = 5.
Fib(5)
Fib(4)
Fib(3)
Fib(2)
Fib(1) Fib(0)
Fib(1)
Fib(2)
Fib(1) Fib(0)
Fib(3)
Fib(2)
Fib(1) Fib(0)
Fib(1)
Let’s say we want to calculate Fibonacci numbers for n = 5.
The recurring problem is considered to have
Overlapping Subproblems if it solves the same
subproblem again and again.
Time Complexity: Recursion
Fib(5)
Fib(4)
Fib(3)
Fib(2)
Fib(1) Fib(0)
Fib(1)
Fib(2)
Fib(1) Fib(0)
Fib(3)
Fib(2)
Fib(1) Fib(0)
Fib(1)
T(n) = T(n-1) + T(n-2) + O(1)
T(n<=1) = O(1)
Overall, T(n) = O(𝟐𝒏)
Depth = 5
Depth = 4
Time Complexity: Recursion
0
2
4
6
8
10
12
14
16
18
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5
Value of n
Time
O(n) = 𝟐𝒏
How Does Dynamic
Programming Work?
How Does Dynamic Programming Work?
Solution: Utilize Memory
Remember the result for each Sub-Problem.
Solving a Subproblem Memory Area
How Does Dynamic Programming Work?
Solution: Utilize Memory
Remember the result for each Sub-Problem.
Memory Area Recurred Subproblem
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.
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
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
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.
What Is Dynamic Programming? | Dynamic Programming Explained | Programming For Beginners|Simplilearn
Ad

Recommended

Dynamic pgmming
Dynamic pgmming
Dr. C.V. Suresh Babu
 
Dynamic programming
Dynamic programming
Yıldırım Tam
 
Travelling salesman dynamic programming
Travelling salesman dynamic programming
maharajdey
 
Dynamic programming
Dynamic programming
Amit Kumar Rathi
 
Greedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Dynamic programming class 16
Dynamic programming class 16
Kumar
 
Insertion sort bubble sort selection sort
Insertion sort bubble sort selection sort
Ummar Hayat
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)
jehan1987
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
unit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming
Dynamic programming
Melaku Bayih Demessie
 
Dynamic Programming
Dynamic Programming
Sahil Kumar
 
Greedy algorithm
Greedy algorithm
International Islamic University
 
Np completeness
Np completeness
Rajendran
 
OPTIMAL BINARY SEARCH
OPTIMAL BINARY SEARCH
Cool Guy
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
Fibonacci Heap
Fibonacci Heap
Anshuman Biswal
 
Daa:Dynamic Programing
Daa:Dynamic Programing
rupali_2bonde
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Np complete
Np complete
Dr. C.V. Suresh Babu
 
Greedy algorithms
Greedy algorithms
Rajendran
 
Branch & bound
Branch & bound
kannanchirayath
 
Matrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
Travelling Salesman Problem
Travelling Salesman Problem
Daniel Raditya
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
Greedy Algorithm
Greedy Algorithm
Waqar Akram
 
Dynamic Programming.pptx
Dynamic Programming.pptx
MuktarHossain13
 
L21_L27_Unit_5_Dynamic_Programming Computer Science
L21_L27_Unit_5_Dynamic_Programming Computer Science
priyanshukumarbt23cs
 

More Related Content

What's hot (20)

Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
unit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic programming
Dynamic programming
Melaku Bayih Demessie
 
Dynamic Programming
Dynamic Programming
Sahil Kumar
 
Greedy algorithm
Greedy algorithm
International Islamic University
 
Np completeness
Np completeness
Rajendran
 
OPTIMAL BINARY SEARCH
OPTIMAL BINARY SEARCH
Cool Guy
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
Fibonacci Heap
Fibonacci Heap
Anshuman Biswal
 
Daa:Dynamic Programing
Daa:Dynamic Programing
rupali_2bonde
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Np complete
Np complete
Dr. C.V. Suresh Babu
 
Greedy algorithms
Greedy algorithms
Rajendran
 
Branch & bound
Branch & bound
kannanchirayath
 
Matrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
Travelling Salesman Problem
Travelling Salesman Problem
Daniel Raditya
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
Greedy Algorithm
Greedy Algorithm
Waqar Akram
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 
unit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
Dynamic Programming
Dynamic Programming
Sahil Kumar
 
Np completeness
Np completeness
Rajendran
 
OPTIMAL BINARY SEARCH
OPTIMAL BINARY SEARCH
Cool Guy
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
Daa:Dynamic Programing
Daa:Dynamic Programing
rupali_2bonde
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Greedy algorithms
Greedy algorithms
Rajendran
 
Matrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals review
ElifTech
 
Travelling Salesman Problem
Travelling Salesman Problem
Daniel Raditya
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
Greedy Algorithm
Greedy Algorithm
Waqar Akram
 

Similar to What Is Dynamic Programming? | Dynamic Programming Explained | Programming For Beginners|Simplilearn (20)

Dynamic Programming.pptx
Dynamic Programming.pptx
MuktarHossain13
 
L21_L27_Unit_5_Dynamic_Programming Computer Science
L21_L27_Unit_5_Dynamic_Programming Computer Science
priyanshukumarbt23cs
 
Dynamic Programing.pptx good for understanding
Dynamic Programing.pptx good for understanding
HUSNAINAHMAD39
 
Elements of Dynamic Programming
Elements of Dynamic Programming
Vishwajeet Shabadi
 
Algorithm lecture Dynamic programming
Algorithm lecture Dynamic programming
rabiul souvon
 
Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisy
ahmed51236
 
Dynamic Programming Intro in Algorithm Design
Dynamic Programming Intro in Algorithm Design
AhsanRazaKolachi
 
Dynamicpgmming
Dynamicpgmming
Muhammad Wasif
 
Annotaed slides for dynamic programming algorithm
Annotaed slides for dynamic programming algorithm
johnathangamal27
 
ADA Unit 2.pptx
ADA Unit 2.pptx
AmanKumar879992
 
W8L1 Introduction & Fibonacci Numbers part 1.pptx
W8L1 Introduction & Fibonacci Numbers part 1.pptx
sakibahmed181234
 
5617723.pptx
5617723.pptx
MatthewMhlongo
 
DynamicProgramming.pptx
DynamicProgramming.pptx
SaimaShaheen14
 
Dynamic programming in Design Analysis and Algorithms
Dynamic programming in Design Analysis and Algorithms
NikunjGoyal20
 
Dynamic programing
Dynamic programing
AniketSingh609353
 
Lecture11
Lecture11
Nv Thejaswini
 
03 dp
03 dp
Pankaj Prateek
 
Algorithm_Dynamic Programming
Algorithm_Dynamic Programming
Im Rafid
 
dynamic-programming unit 3 power point presentation
dynamic-programming unit 3 power point presentation
Shrinivasa6
 
Dynamic programming
Dynamic programming
Jay Nagar
 
Dynamic Programming.pptx
Dynamic Programming.pptx
MuktarHossain13
 
L21_L27_Unit_5_Dynamic_Programming Computer Science
L21_L27_Unit_5_Dynamic_Programming Computer Science
priyanshukumarbt23cs
 
Dynamic Programing.pptx good for understanding
Dynamic Programing.pptx good for understanding
HUSNAINAHMAD39
 
Elements of Dynamic Programming
Elements of Dynamic Programming
Vishwajeet Shabadi
 
Algorithm lecture Dynamic programming
Algorithm lecture Dynamic programming
rabiul souvon
 
Dynamic programming prasintation eaisy
Dynamic programming prasintation eaisy
ahmed51236
 
Dynamic Programming Intro in Algorithm Design
Dynamic Programming Intro in Algorithm Design
AhsanRazaKolachi
 
Annotaed slides for dynamic programming algorithm
Annotaed slides for dynamic programming algorithm
johnathangamal27
 
W8L1 Introduction & Fibonacci Numbers part 1.pptx
W8L1 Introduction & Fibonacci Numbers part 1.pptx
sakibahmed181234
 
DynamicProgramming.pptx
DynamicProgramming.pptx
SaimaShaheen14
 
Dynamic programming in Design Analysis and Algorithms
Dynamic programming in Design Analysis and Algorithms
NikunjGoyal20
 
Algorithm_Dynamic Programming
Algorithm_Dynamic Programming
Im Rafid
 
dynamic-programming unit 3 power point presentation
dynamic-programming unit 3 power point presentation
Shrinivasa6
 
Dynamic programming
Dynamic programming
Jay Nagar
 
Ad

More from Simplilearn (20)

Top 50 Scrum Master Interview Questions | Scrum Master Interview Questions & ...
Top 50 Scrum Master Interview Questions | Scrum Master Interview Questions & ...
Simplilearn
 
Bagging Vs Boosting In Machine Learning | Ensemble Learning In Machine Learni...
Bagging Vs Boosting In Machine Learning | Ensemble Learning In Machine Learni...
Simplilearn
 
Future Of Social Media | Social Media Trends and Strategies 2025 | Instagram ...
Future Of Social Media | Social Media Trends and Strategies 2025 | Instagram ...
Simplilearn
 
SQL Query Optimization | SQL Query Optimization Techniques | SQL Basics | SQL...
SQL Query Optimization | SQL Query Optimization Techniques | SQL Basics | SQL...
Simplilearn
 
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
Simplilearn
 
How To Start Influencer Marketing Business | Influencer Marketing For Beginne...
How To Start Influencer Marketing Business | Influencer Marketing For Beginne...
Simplilearn
 
Cyber Security Roadmap 2025 | How To Become Cyber Security Engineer In 2025 |...
Cyber Security Roadmap 2025 | How To Become Cyber Security Engineer In 2025 |...
Simplilearn
 
How To Become An AI And ML Engineer In 2025 | AI Engineer Roadmap | AI ML Car...
How To Become An AI And ML Engineer In 2025 | AI Engineer Roadmap | AI ML Car...
Simplilearn
 
What Is GitHub Copilot? | How To Use GitHub Copilot? | How does GitHub Copilo...
What Is GitHub Copilot? | How To Use GitHub Copilot? | How does GitHub Copilo...
Simplilearn
 
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Top 7 High Paying AI Certifications Courses For 2025 | Best AI Certifications...
Top 7 High Paying AI Certifications Courses For 2025 | Best AI Certifications...
Simplilearn
 
Data Cleaning In Data Mining | Step by Step Data Cleaning Process | Data Clea...
Data Cleaning In Data Mining | Step by Step Data Cleaning Process | Data Clea...
Simplilearn
 
Top 10 Data Analyst Projects For 2025 | Data Analyst Projects | Data Analysis...
Top 10 Data Analyst Projects For 2025 | Data Analyst Projects | Data Analysis...
Simplilearn
 
AI Engineer Roadmap 2025 | AI Engineer Roadmap For Beginners | AI Engineer Ca...
AI Engineer Roadmap 2025 | AI Engineer Roadmap For Beginners | AI Engineer Ca...
Simplilearn
 
Machine Learning Roadmap 2025 | Machine Learning Engineer Roadmap For Beginne...
Machine Learning Roadmap 2025 | Machine Learning Engineer Roadmap For Beginne...
Simplilearn
 
Kotter's 8-Step Change Model Explained | Kotter's Change Management Model | S...
Kotter's 8-Step Change Model Explained | Kotter's Change Management Model | S...
Simplilearn
 
Gen AI Engineer Roadmap For 2025 | How To Become Gen AI Engineer In 2025 | Si...
Gen AI Engineer Roadmap For 2025 | How To Become Gen AI Engineer In 2025 | Si...
Simplilearn
 
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Top 50 Scrum Master Interview Questions | Scrum Master Interview Questions & ...
Top 50 Scrum Master Interview Questions | Scrum Master Interview Questions & ...
Simplilearn
 
Bagging Vs Boosting In Machine Learning | Ensemble Learning In Machine Learni...
Bagging Vs Boosting In Machine Learning | Ensemble Learning In Machine Learni...
Simplilearn
 
Future Of Social Media | Social Media Trends and Strategies 2025 | Instagram ...
Future Of Social Media | Social Media Trends and Strategies 2025 | Instagram ...
Simplilearn
 
SQL Query Optimization | SQL Query Optimization Techniques | SQL Basics | SQL...
SQL Query Optimization | SQL Query Optimization Techniques | SQL Basics | SQL...
Simplilearn
 
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
Simplilearn
 
How To Start Influencer Marketing Business | Influencer Marketing For Beginne...
How To Start Influencer Marketing Business | Influencer Marketing For Beginne...
Simplilearn
 
Cyber Security Roadmap 2025 | How To Become Cyber Security Engineer In 2025 |...
Cyber Security Roadmap 2025 | How To Become Cyber Security Engineer In 2025 |...
Simplilearn
 
How To Become An AI And ML Engineer In 2025 | AI Engineer Roadmap | AI ML Car...
How To Become An AI And ML Engineer In 2025 | AI Engineer Roadmap | AI ML Car...
Simplilearn
 
What Is GitHub Copilot? | How To Use GitHub Copilot? | How does GitHub Copilo...
What Is GitHub Copilot? | How To Use GitHub Copilot? | How does GitHub Copilo...
Simplilearn
 
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Top 7 High Paying AI Certifications Courses For 2025 | Best AI Certifications...
Top 7 High Paying AI Certifications Courses For 2025 | Best AI Certifications...
Simplilearn
 
Data Cleaning In Data Mining | Step by Step Data Cleaning Process | Data Clea...
Data Cleaning In Data Mining | Step by Step Data Cleaning Process | Data Clea...
Simplilearn
 
Top 10 Data Analyst Projects For 2025 | Data Analyst Projects | Data Analysis...
Top 10 Data Analyst Projects For 2025 | Data Analyst Projects | Data Analysis...
Simplilearn
 
AI Engineer Roadmap 2025 | AI Engineer Roadmap For Beginners | AI Engineer Ca...
AI Engineer Roadmap 2025 | AI Engineer Roadmap For Beginners | AI Engineer Ca...
Simplilearn
 
Machine Learning Roadmap 2025 | Machine Learning Engineer Roadmap For Beginne...
Machine Learning Roadmap 2025 | Machine Learning Engineer Roadmap For Beginne...
Simplilearn
 
Kotter's 8-Step Change Model Explained | Kotter's Change Management Model | S...
Kotter's 8-Step Change Model Explained | Kotter's Change Management Model | S...
Simplilearn
 
Gen AI Engineer Roadmap For 2025 | How To Become Gen AI Engineer In 2025 | Si...
Gen AI Engineer Roadmap For 2025 | How To Become Gen AI Engineer In 2025 | Si...
Simplilearn
 
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Ad

Recently uploaded (20)

SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
JHS SHS Back to School 2024-2025 .pptx
JHS SHS Back to School 2024-2025 .pptx
melvinapay78
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Measuring, learning and applying multiplication facts.
Measuring, learning and applying multiplication facts.
cgilmore6
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
JHS SHS Back to School 2024-2025 .pptx
JHS SHS Back to School 2024-2025 .pptx
melvinapay78
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 

What Is Dynamic Programming? | Dynamic Programming Explained | Programming For Beginners|Simplilearn

  • 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
  • 3. Real-Life Example of Dynamic Programming
  • 4. Click here to watch the video
  • 5. This is Rachael. She loves solving complex puzzles.
  • 6. While searching through her puzzle book, she came across a tic-tac-toe puzzle.
  • 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?
  • 18. Dynamic Programming Interpretation of Fibonacci Series Program
  • 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.
  • 23. Fib(5) Fib(4) Fib(3) Fib(2) Fib(1) Fib(0) Fib(1) Fib(2) Fib(1) Fib(0) Fib(3) Fib(2) Fib(1) Fib(0) Fib(1) Let’s say we want to calculate Fibonacci numbers for n = 5.
  • 24. Fib(5) Fib(4) Fib(3) Fib(2) Fib(1) Fib(0) Fib(1) Fib(2) Fib(1) Fib(0) Fib(3) Fib(2) Fib(1) Fib(0) Fib(1) Let’s say we want to calculate Fibonacci numbers for n = 5. The recurring problem is considered to have Overlapping Subproblems if it solves the same subproblem again and again.
  • 25. Time Complexity: Recursion Fib(5) Fib(4) Fib(3) Fib(2) Fib(1) Fib(0) Fib(1) Fib(2) Fib(1) Fib(0) Fib(3) Fib(2) Fib(1) Fib(0) Fib(1) T(n) = T(n-1) + T(n-2) + O(1) T(n<=1) = O(1) Overall, T(n) = O(𝟐𝒏) Depth = 5 Depth = 4
  • 26. Time Complexity: Recursion 0 2 4 6 8 10 12 14 16 18 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 Value of n Time O(n) = 𝟐𝒏
  • 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.