SlideShare ist ein Scribd-Unternehmen logo
1 von 34
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

Weitere ähnliche Inhalte

Was ist angesagt?

Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approachpadmeshagrekar
 
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 OptimalityBhavin Darji
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Travelling SalesMan Problem(TSP)
Travelling SalesMan Problem(TSP)Travelling SalesMan Problem(TSP)
Travelling SalesMan Problem(TSP)Akshay Kamble
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingGopi Saiteja
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsackAmin Omi
 
Np completeness
Np completenessNp completeness
Np completenessRajendran
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic ProgrammingFenil Shah
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms SURBHI SAROHA
 
implementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptimplementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptAntaraBhattacharya12
 
Introduction to Approximation Algorithms
Introduction to Approximation AlgorithmsIntroduction to Approximation Algorithms
Introduction to Approximation AlgorithmsJhoirene Clemente
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationRespa Peter
 

Was ist angesagt? (20)

Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
Backtracking
BacktrackingBacktracking
Backtracking
 
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
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Travelling SalesMan Problem(TSP)
Travelling SalesMan Problem(TSP)Travelling SalesMan Problem(TSP)
Travelling SalesMan Problem(TSP)
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
0/1 knapsack
0/1 knapsack0/1 knapsack
0/1 knapsack
 
Np completeness
Np completenessNp completeness
Np completeness
 
01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming01 Knapsack using Dynamic Programming
01 Knapsack using Dynamic Programming
 
Np complete
Np completeNp complete
Np complete
 
P vs NP
P vs NP P vs NP
P vs NP
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms Dynamic programming, Branch and bound algorithm & Greedy algorithms
Dynamic programming, Branch and bound algorithm & Greedy algorithms
 
implementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptimplementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity ppt
 
Introduction to Approximation Algorithms
Introduction to Approximation AlgorithmsIntroduction to Approximation Algorithms
Introduction to Approximation Algorithms
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 

Ähnlich wie 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 programmingXochitl Watts
 
Algorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingAlgorithm_Dynamic Programming
Algorithm_Dynamic ProgrammingIm 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 methodJyoReddy9
 
lecture4-recursion.pptx
lecture4-recursion.pptxlecture4-recursion.pptx
lecture4-recursion.pptxLizhen Shi
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingJay 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 LearningPranav Ainavolu
 
Balaji-opt-lecture6-act.ppt
Balaji-opt-lecture6-act.pptBalaji-opt-lecture6-act.ppt
Balaji-opt-lecture6-act.pptJamesGreen666883
 
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 SaghafiProfessor Lili Saghafi
 
Dynamic Programming: Smith-Waterman
Dynamic Programming: Smith-WatermanDynamic Programming: Smith-Waterman
Dynamic Programming: Smith-WatermanRohan 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.pptx15AnasKhan
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptxMuktarHossain13
 
Introduction to Dynamic Programming.pptx
Introduction to Dynamic Programming.pptxIntroduction to Dynamic Programming.pptx
Introduction to Dynamic Programming.pptxPochupouOwo
 
Sure interview algorithm-1103
Sure interview algorithm-1103Sure interview algorithm-1103
Sure interview algorithm-1103Sure Interview
 
Python recursion
Python recursionPython recursion
Python recursionToniyaP1
 

Ähnlich wie 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
 

Mehr von Simplilearn

ChatGPT in Cybersecurity
ChatGPT in CybersecurityChatGPT in Cybersecurity
ChatGPT in CybersecuritySimplilearn
 
Whatis SQL Injection.pptx
Whatis SQL Injection.pptxWhatis SQL Injection.pptx
Whatis SQL Injection.pptxSimplilearn
 
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 2024Simplilearn
 
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
 
How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...
How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...
How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...Simplilearn
 
Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...
Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...
Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...Simplilearn
 
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...Simplilearn
 
Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...
Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...
Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...Simplilearn
 
React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...
React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...
React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...Simplilearn
 
What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...
What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...
What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...Simplilearn
 
How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...
How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...
How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...Simplilearn
 
WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...
WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...
WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...Simplilearn
 
Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...
Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...
Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...Simplilearn
 
How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...
How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...
How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...Simplilearn
 
How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...
How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...
How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...Simplilearn
 

Mehr von Simplilearn (20)

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...
 
How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...
How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...
How to Become a Business Analyst ?| Roadmap to Become Business Analyst | Simp...
 
Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...
Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...
Career Opportunities In Artificial Intelligence 2023 | AI Job Opportunities |...
 
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
Programming for Beginners | How to Start Coding in 2023? | Introduction to Pr...
 
Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...
Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...
Best IDE for Programming in 2023 | Top 8 Programming IDE You Should Know | Si...
 
React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...
React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...
React 18 Overview | React 18 New Features and Changes | React 18 Tutorial 202...
 
What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...
What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...
What Is Next JS ? | Introduction to Next JS | Basics of Next JS | Next JS Tut...
 
How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...
How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...
How To Become an SEO Expert In 2023 | SEO Expert Tutorial | SEO For Beginners...
 
WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...
WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...
WordPress Tutorial for Beginners 2023 | What Is WordPress and How Does It Wor...
 
Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...
Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...
Blogging For Beginners 2023 | How To Create A Blog | Blogging Tutorial | Simp...
 
How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...
How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...
How To Start A Blog In 2023 | Pros And Cons Of Blogging | Blogging Tutorial |...
 
How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...
How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...
How to Increase Website Traffic ? | 10 Ways To Increase Website Traffic in 20...
 

Kürzlich hochgeladen

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 

Kürzlich hochgeladen (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

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.