SlideShare a Scribd company logo
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

More Related Content

What's hot

Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
Nv Thejaswini
 
Randomized Algorithms
Randomized AlgorithmsRandomized Algorithms
Randomized Algorithms
Ketan Kamra
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
Krish_ver2
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
Waqar Akram
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
Algorithm paradigms
Algorithm paradigmsAlgorithm paradigms
Algorithm paradigms
suresh5c2
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Amit Kumar Rathi
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
Krish_ver2
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
Fahim Ferdous
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using  divide & conquer finding Min and max element from given array using  divide & conquer
finding Min and max element from given array using divide & conquer
Swati Kulkarni Jaipurkar
 
Np completeness
Np completenessNp completeness
Np completeness
Rajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
sandeep54552
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
padmeshagrekar
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
Abhimanyu Mishra
 
Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
Darshit Metaliya
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 

What's hot (20)

Unit 2 in daa
Unit 2 in daaUnit 2 in daa
Unit 2 in daa
 
Randomized Algorithms
Randomized AlgorithmsRandomized Algorithms
Randomized Algorithms
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Algorithm paradigms
Algorithm paradigmsAlgorithm paradigms
Algorithm paradigms
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using  divide & conquer finding Min and max element from given array using  divide & conquer
finding Min and max element from given array using divide & conquer
 
Np completeness
Np completenessNp completeness
Np completeness
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Longest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) AlgorithmLongest Common Subsequence (LCS) Algorithm
Longest Common Subsequence (LCS) Algorithm
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Np complete
Np completeNp complete
Np complete
 

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

Algorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programmingAlgorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programming
Xochitl Watts
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic Programming
Im Rafid
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
JyoReddy9
 
Lecture9 recursion
Lecture9 recursionLecture9 recursion
Lecture9 recursion
Muhammad Zubair
 
ADA Unit 2.pptx
ADA Unit 2.pptxADA Unit 2.pptx
ADA Unit 2.pptx
AmanKumar879992
 
6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx
Venkateswara Babu Ravipati
 
lecture4-recursion.pptx
lecture4-recursion.pptxlecture4-recursion.pptx
lecture4-recursion.pptx
Lizhen Shi
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Jay Nagar
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13Terry Yoast
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine Learning
Pranav Ainavolu
 
Balaji-opt-lecture6-act.ppt
Balaji-opt-lecture6-act.pptBalaji-opt-lecture6-act.ppt
Balaji-opt-lecture6-act.ppt
JamesGreen666883
 
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiEffective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Professor Lili Saghafi
 
Dynamic Programming: Smith-Waterman
Dynamic Programming: Smith-WatermanDynamic Programming: Smith-Waterman
Dynamic Programming: Smith-Waterman
Rohan Prakash
 
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
15AnasKhan
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
MuktarHossain13
 
Introduction to Dynamic Programming.pptx
Introduction to Dynamic Programming.pptxIntroduction to Dynamic Programming.pptx
Introduction to Dynamic Programming.pptx
PochupouOwo
 
Sure interview algorithm-1103
Sure interview algorithm-1103Sure interview algorithm-1103
Sure interview algorithm-1103Sure Interview
 
Python recursion
Python recursionPython recursion
Python recursion
ToniyaP1
 

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

Algorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programmingAlgorithms practice and problem solving - dynamic programming
Algorithms practice and problem solving - dynamic programming
 
Dynamicpgmming
DynamicpgmmingDynamicpgmming
Dynamicpgmming
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic Programming
 
Module 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer methodModule 2ppt.pptx divid and conquer method
Module 2ppt.pptx divid and conquer method
 
Lecture9 recursion
Lecture9 recursionLecture9 recursion
Lecture9 recursion
 
ADA Unit 2.pptx
ADA Unit 2.pptxADA Unit 2.pptx
ADA Unit 2.pptx
 
6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx6-Python-Recursion PPT.pptx
6-Python-Recursion PPT.pptx
 
lecture4-recursion.pptx
lecture4-recursion.pptxlecture4-recursion.pptx
lecture4-recursion.pptx
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine Learning
 
Balaji-opt-lecture6-act.ppt
Balaji-opt-lecture6-act.pptBalaji-opt-lecture6-act.ppt
Balaji-opt-lecture6-act.ppt
 
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili SaghafiEffective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
Effective Algorithm for n Fibonacci Number By: Professor Lili Saghafi
 
Dynamic programing
Dynamic programingDynamic programing
Dynamic programing
 
Dynamic Programming: Smith-Waterman
Dynamic Programming: Smith-WatermanDynamic Programming: Smith-Waterman
Dynamic Programming: Smith-Waterman
 
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
35000120060_Nitesh Modi_CSE Presentation on recursion.pptx
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
 
Introduction to Dynamic Programming.pptx
Introduction to Dynamic Programming.pptxIntroduction to Dynamic Programming.pptx
Introduction to Dynamic Programming.pptx
 
Sure interview algorithm-1103
Sure interview algorithm-1103Sure interview algorithm-1103
Sure interview algorithm-1103
 
Python recursion
Python recursionPython recursion
Python recursion
 

More from Simplilearn

🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...
🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...
🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...
Simplilearn
 
Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...
Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...
Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...
Simplilearn
 
How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...
How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...
How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...
Simplilearn
 
Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...
Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...
Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...
Simplilearn
 
🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...
🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...
🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...
Simplilearn
 
🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...
🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...
🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...
Simplilearn
 
🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...
🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...
🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...
Simplilearn
 
🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...
🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...
🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...
Simplilearn
 
Project Manager vs Program Manager - What’s the Difference ? | Project Manage...
Project Manager vs Program Manager - What’s the Difference ? | Project Manage...Project Manager vs Program Manager - What’s the Difference ? | Project Manage...
Project Manager vs Program Manager - What’s the Difference ? | Project Manage...
Simplilearn
 
Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...
Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...
Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...
Simplilearn
 
🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn
🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn
🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn
Simplilearn
 
ChatGPT in Cybersecurity
ChatGPT in CybersecurityChatGPT in Cybersecurity
ChatGPT in Cybersecurity
Simplilearn
 
Whatis SQL Injection.pptx
Whatis SQL Injection.pptxWhatis SQL Injection.pptx
Whatis SQL Injection.pptx
Simplilearn
 
Top 5 High Paying Cloud Computing Jobs in 2023
 Top 5 High Paying Cloud Computing Jobs in 2023  Top 5 High Paying Cloud Computing Jobs in 2023
Top 5 High Paying Cloud Computing Jobs in 2023
Simplilearn
 
Types Of Cloud Jobs In 2024
Types Of Cloud Jobs In 2024Types Of Cloud Jobs In 2024
Types Of Cloud Jobs In 2024
Simplilearn
 
Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...
Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...
Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...
Simplilearn
 
What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...
What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...
What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...
Simplilearn
 
Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...
Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...
Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...
Simplilearn
 
React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...
React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...
React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...
Simplilearn
 
Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...
Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...
Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...
Simplilearn
 

More from Simplilearn (20)

🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...
🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...
🔥 Cyber Security Engineer Vs Ethical Hacker: What's The Difference | Cybersec...
 
Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...
Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...
Top 10 Companies Hiring Machine Learning Engineer | Machine Learning Jobs | A...
 
How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...
How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...
How to Become Strategy Manager 2023 ? | Strategic Management | Roadmap | Simp...
 
Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...
Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...
Top 20 Devops Engineer Interview Questions And Answers For 2023 | Devops Tuto...
 
🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...
🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...
🔥 Big Data Engineer Roadmap 2023 | How To Become A Big Data Engineer In 2023 ...
 
🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...
🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...
🔥 AI Engineer Resume For 2023 | CV For AI Engineer | AI Engineer CV 2023 | Si...
 
🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...
🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...
🔥 Top 5 Skills For Data Engineer In 2023 | Data Engineer Skills Required For ...
 
🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...
🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...
🔥 6 Reasons To Become A Data Engineer | Why You Should Become A Data Engineer...
 
Project Manager vs Program Manager - What’s the Difference ? | Project Manage...
Project Manager vs Program Manager - What’s the Difference ? | Project Manage...Project Manager vs Program Manager - What’s the Difference ? | Project Manage...
Project Manager vs Program Manager - What’s the Difference ? | Project Manage...
 
Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...
Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...
Deloitte Interview Questions And Answers | Top 45 Deloitte Interview Question...
 
🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn
🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn
🔥 Deep Learning Roadmap 2024 | Deep Learning Career Path 2024 | Simplilearn
 
ChatGPT in Cybersecurity
ChatGPT in CybersecurityChatGPT in Cybersecurity
ChatGPT in Cybersecurity
 
Whatis SQL Injection.pptx
Whatis SQL Injection.pptxWhatis SQL Injection.pptx
Whatis SQL Injection.pptx
 
Top 5 High Paying Cloud Computing Jobs in 2023
 Top 5 High Paying Cloud Computing Jobs in 2023  Top 5 High Paying Cloud Computing Jobs in 2023
Top 5 High Paying Cloud Computing Jobs in 2023
 
Types Of Cloud Jobs In 2024
Types Of Cloud Jobs In 2024Types Of Cloud Jobs In 2024
Types Of Cloud Jobs In 2024
 
Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...
Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...
Top 12 AI Technologies To Learn 2024 | Top AI Technologies in 2024 | AI Trend...
 
What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...
What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...
What is LSTM ?| Long Short Term Memory Explained with Example | Deep Learning...
 
Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...
Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...
Top 10 Chat GPT Use Cases | ChatGPT Applications | ChatGPT Tutorial For Begin...
 
React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...
React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...
React JS Vs Next JS - What's The Difference | Next JS Tutorial For Beginners ...
 
Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...
Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...
Backpropagation in Neural Networks | Back Propagation Algorithm with Examples...
 

Recently uploaded

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

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
  • 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.