SlideShare a Scribd company logo
WELCOME TO OUR PRESENTATION
GROUP MEMBER LIST
 Abu Nowshad Rasel 161-15-6861
 Shahrun Siddique Taki 161-15-7195
 Syeda Khadizatul Maria 161-15-7333
 Md. Mehedi Hassan 161-15-7338
Coin Change : Greedy vs
Dynamic Programming
PRESENTATION TOPIC
Greedy Algorithm
 What is greedy algorithm ?
 An algorithm is greedy if it builds a solution in small
steps , choosing a decision at each step
myopically[=locally, not considering what happen ahead to
optimize some underlying criterion.
 It is easy to design a greedy algorithm for a problem .
There may be different ways to choose the next step
locally.
Coin Change Problem
Coin Change is the problem of finding the number of ways of making
changes for a particular amount of taka, n, using a given unlimited
amounts of coins.
Example :
Available coins : ৳1, ৳5, ৳10, ৳25
Make change : ৳48
∴ 48 - 25 = 23 →
23 - 10 = 13 →
13 - 10 = 3 →
3 - 1*3 = 0 →
25
10
10
111
Result :
 Number of coins requires to make change to 48 = 6
 Coin set = { 1,1,1,10,10,25 }
Advantage of greedy
#Greedy is easy to be implemented. Just search the
Best choice from the current state that reachable .
#In simple case, greedy often give the best solution.
Failure of Greedy Algorithm
A greedy algorithm is a simple but in many
problems, a greedy strategy does not produce
an optimal solution. The greedy algorithm
fails to find optimal solution in some case,
because it makes decisions based only on the
information it has at any one step, and
without regard to the overall problem.
In coin change problem , if every coin is a
multiple of all smaller coins, then we can use
greedy approach to get the optimal solution.
In some fictional monetary system :
Available coins : 1,7,10
Make change :15 taka
∴ 15 - 10 = 5 →
5 - 1*5 = 0 →
This requires six coins .
A better solution would be to use two 7 taka and one 1 taka
+ + = 15
This only requires three coins
10
1 1 1 1 1
7 7 1
For example :
Available coins : 4,10,25
Make change : 41 taka
∴ 41 - 25 = 16 →
16 - 10 = 6 →
6- 4 = 2 →
2 → ??
In this case , greedy algorithm fail to solve . But the
required result is one 25 taka and four 4 taka.
So the greedy algorithm does not give an optimal
solution always.
25
10
4
Another example:
Dynamic Programming
Dynamic programming (also known as dynamic
optimization) is a method for solving a complex problem
by breaking it down into a collection of simpler
subproblems, solving each of those subproblems just
once, and storing their solutions
DP is used to solve problems with the following
characteristics:
 Simple Subproblems
 Optimal structure of the problems
 Overplapping sub-problems
Dynamic Programming Solution (4 steps)
 1. Characterize the structure of an optimal solution.
 2. Recursively define the value of an optimal solution.
 3. Compute the value of an optimal solution in a bottom-up
fashion.
 4. Construct an optimal solution from computed information
Greedy vs. DP
 Similarities
Optimization problems
Optimal substructure
Make choice at each step
Differences
 Dynamic Programming is Bottom up while Greedy is top-down -Optimal substructure
Dynamic programming can be overkill; greedy algorithms tend to be easier to code
Coin Change With Dynamic Programming
 Make a change, Total = 6
 Available Coin Set = { 2, 3, 5 }
T[i] [j] is the 2D array to denote the minimum number of coins require to make the
change Coin[i] is the sorted array of available coin sets. [Index Start from 1]
 If V == 0, then 0 coins required.
T[i][j] = 0
 If V > 0
Case 1: T [i][j] = T [i-1][j] If Coin[i] is not takes
Case 2: T [i][j] = 1 + T [i] [j–Coin [i]] If Coin[ i ] is taken
T [i][j] = MIN ( T [i-1][j] , 1 + T[i][j-Coin[i] )
0 1 2 3 4 5 6
2
3
5
0
0
0
0
∞ ∞ ∞ ∞ ∞ ∞
∞ 1 ∞ 2 ∞ 3
∞
∞ 1 1 2 1 2
1 1 2 2 2
Result:
 Number of Coins requires to make a change to 6 = 2
 Coin Set = { 3, 3 }
Thank You
Ad

More Related Content

What's hot (20)

Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Coin Change Problem
Coin Change ProblemCoin Change Problem
Coin Change Problem
DEVTYPE
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
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
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
sandeep54552
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
Jayesh Chauhan
 
Min-Max algorithm
Min-Max algorithmMin-Max algorithm
Min-Max algorithm
Dr. C.V. Suresh Babu
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
Rajendra Dangwal
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Dr Shashikant Athawale
 
Randomized Algorithm- Advanced Algorithm
Randomized Algorithm- Advanced AlgorithmRandomized Algorithm- Advanced Algorithm
Randomized Algorithm- Advanced Algorithm
Mahbubur Rahman
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
04 brute force
04 brute force04 brute force
04 brute force
Hira Gul
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
Ruchika Sinha
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Shakil Ahmed
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
Muhammad Amjad Rana
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Coin Change Problem
Coin Change ProblemCoin Change Problem
Coin Change Problem
DEVTYPE
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Rajendran
 
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
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
Jayesh Chauhan
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Randomized Algorithm- Advanced Algorithm
Randomized Algorithm- Advanced AlgorithmRandomized Algorithm- Advanced Algorithm
Randomized Algorithm- Advanced Algorithm
Mahbubur Rahman
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
04 brute force
04 brute force04 brute force
04 brute force
Hira Gul
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Greedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.pptGreedy with Task Scheduling Algorithm.ppt
Greedy with Task Scheduling Algorithm.ppt
Ruchika Sinha
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Shakil Ahmed
 

Similar to Coin Change : Greedy vs Dynamic Programming (20)

Coding Concept.ppt
Coding Concept.pptCoding Concept.ppt
Coding Concept.ppt
ssuser3b64952
 
DynamicProgramming.pptx
DynamicProgramming.pptxDynamicProgramming.pptx
DynamicProgramming.pptx
SaimaShaheen14
 
dynamic-programming unit 3 power point presentation
dynamic-programming unit 3 power point presentationdynamic-programming unit 3 power point presentation
dynamic-programming unit 3 power point presentation
Shrinivasa6
 
Introduction to Algorithm Design and Analysis.pdf
Introduction to Algorithm Design and Analysis.pdfIntroduction to Algorithm Design and Analysis.pdf
Introduction to Algorithm Design and Analysis.pdf
Kiran K
 
Linear Programming
Linear ProgrammingLinear Programming
Linear Programming
Pulchowk Campus
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
chidabdu
 
32 algorithm-types
32 algorithm-types32 algorithm-types
32 algorithm-types
ashish bansal
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem SolvingStd 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
Nuzhat Memon
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Jay Patel
 
Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...
Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...
Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...
kongara
 
Coin change using dp
Coin change using dpCoin change using dp
Coin change using dp
arfin97
 
Greedymethod
GreedymethodGreedymethod
Greedymethod
Meenakshi Devi
 
013-number-theory-properties-in-science.pdf
013-number-theory-properties-in-science.pdf013-number-theory-properties-in-science.pdf
013-number-theory-properties-in-science.pdf
verdemarco991
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
jinalgoti
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
UrviBhalani2
 
Daa unit 2
Daa unit 2Daa unit 2
Daa unit 2
snehajiyani
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
Low Ying Hao
 
Should a football team go for a one or two point conversion? A dynamic progra...
Should a football team go for a one or two point conversion? A dynamic progra...Should a football team go for a one or two point conversion? A dynamic progra...
Should a football team go for a one or two point conversion? A dynamic progra...
Laura Albert
 
Dynamic Itemset Counting
Dynamic Itemset CountingDynamic Itemset Counting
Dynamic Itemset Counting
Tarat Diloksawatdikul
 
Dynamic Itemset Counting
Dynamic Itemset CountingDynamic Itemset Counting
Dynamic Itemset Counting
Tarat Diloksawatdikul
 
DynamicProgramming.pptx
DynamicProgramming.pptxDynamicProgramming.pptx
DynamicProgramming.pptx
SaimaShaheen14
 
dynamic-programming unit 3 power point presentation
dynamic-programming unit 3 power point presentationdynamic-programming unit 3 power point presentation
dynamic-programming unit 3 power point presentation
Shrinivasa6
 
Introduction to Algorithm Design and Analysis.pdf
Introduction to Algorithm Design and Analysis.pdfIntroduction to Algorithm Design and Analysis.pdf
Introduction to Algorithm Design and Analysis.pdf
Kiran K
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
chidabdu
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem SolvingStd 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
Nuzhat Memon
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Jay Patel
 
Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...
Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...
Quantitativetechniqueformanagerialdecisionlinearprogramming 090725035417-phpa...
kongara
 
Coin change using dp
Coin change using dpCoin change using dp
Coin change using dp
arfin97
 
013-number-theory-properties-in-science.pdf
013-number-theory-properties-in-science.pdf013-number-theory-properties-in-science.pdf
013-number-theory-properties-in-science.pdf
verdemarco991
 
Algorithm Using Divide And Conquer
Algorithm Using Divide And ConquerAlgorithm Using Divide And Conquer
Algorithm Using Divide And Conquer
UrviBhalani2
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
Low Ying Hao
 
Should a football team go for a one or two point conversion? A dynamic progra...
Should a football team go for a one or two point conversion? A dynamic progra...Should a football team go for a one or two point conversion? A dynamic progra...
Should a football team go for a one or two point conversion? A dynamic progra...
Laura Albert
 
Ad

More from Syeda Khadizatul maria (7)

Myself
MyselfMyself
Myself
Syeda Khadizatul maria
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
Syeda Khadizatul maria
 
Black box testing
Black box testingBlack box testing
Black box testing
Syeda Khadizatul maria
 
Honeypot
HoneypotHoneypot
Honeypot
Syeda Khadizatul maria
 
Gene expression-analysis
Gene expression-analysis Gene expression-analysis
Gene expression-analysis
Syeda Khadizatul maria
 
Book review
Book reviewBook review
Book review
Syeda Khadizatul maria
 
Currency converter
Currency converterCurrency converter
Currency converter
Syeda Khadizatul maria
 
Ad

Recently uploaded (20)

How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
Cyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top QuestionsCyber security COPA ITI MCQ Top Questions
Cyber security COPA ITI MCQ Top Questions
SONU HEETSON
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
COPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDFCOPA Apprentice exam Questions and answers PDF
COPA Apprentice exam Questions and answers PDF
SONU HEETSON
 
Look Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History EverywhereLook Up, Look Down: Spotting Local History Everywhere
Look Up, Look Down: Spotting Local History Everywhere
History of Stoke Newington
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 

Coin Change : Greedy vs Dynamic Programming

  • 1. WELCOME TO OUR PRESENTATION
  • 2. GROUP MEMBER LIST  Abu Nowshad Rasel 161-15-6861  Shahrun Siddique Taki 161-15-7195  Syeda Khadizatul Maria 161-15-7333  Md. Mehedi Hassan 161-15-7338
  • 3. Coin Change : Greedy vs Dynamic Programming PRESENTATION TOPIC
  • 4. Greedy Algorithm  What is greedy algorithm ?  An algorithm is greedy if it builds a solution in small steps , choosing a decision at each step myopically[=locally, not considering what happen ahead to optimize some underlying criterion.  It is easy to design a greedy algorithm for a problem . There may be different ways to choose the next step locally.
  • 5. Coin Change Problem Coin Change is the problem of finding the number of ways of making changes for a particular amount of taka, n, using a given unlimited amounts of coins. Example : Available coins : ৳1, ৳5, ৳10, ৳25 Make change : ৳48 ∴ 48 - 25 = 23 → 23 - 10 = 13 → 13 - 10 = 3 → 3 - 1*3 = 0 → 25 10 10 111
  • 6. Result :  Number of coins requires to make change to 48 = 6  Coin set = { 1,1,1,10,10,25 }
  • 7. Advantage of greedy #Greedy is easy to be implemented. Just search the Best choice from the current state that reachable . #In simple case, greedy often give the best solution.
  • 8. Failure of Greedy Algorithm A greedy algorithm is a simple but in many problems, a greedy strategy does not produce an optimal solution. The greedy algorithm fails to find optimal solution in some case, because it makes decisions based only on the information it has at any one step, and without regard to the overall problem. In coin change problem , if every coin is a multiple of all smaller coins, then we can use greedy approach to get the optimal solution.
  • 9. In some fictional monetary system : Available coins : 1,7,10 Make change :15 taka ∴ 15 - 10 = 5 → 5 - 1*5 = 0 → This requires six coins . A better solution would be to use two 7 taka and one 1 taka + + = 15 This only requires three coins 10 1 1 1 1 1 7 7 1 For example :
  • 10. Available coins : 4,10,25 Make change : 41 taka ∴ 41 - 25 = 16 → 16 - 10 = 6 → 6- 4 = 2 → 2 → ?? In this case , greedy algorithm fail to solve . But the required result is one 25 taka and four 4 taka. So the greedy algorithm does not give an optimal solution always. 25 10 4 Another example:
  • 11. Dynamic Programming Dynamic programming (also known as dynamic optimization) is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions DP is used to solve problems with the following characteristics:  Simple Subproblems  Optimal structure of the problems  Overplapping sub-problems
  • 12. Dynamic Programming Solution (4 steps)  1. Characterize the structure of an optimal solution.  2. Recursively define the value of an optimal solution.  3. Compute the value of an optimal solution in a bottom-up fashion.  4. Construct an optimal solution from computed information
  • 13. Greedy vs. DP  Similarities Optimization problems Optimal substructure Make choice at each step Differences  Dynamic Programming is Bottom up while Greedy is top-down -Optimal substructure Dynamic programming can be overkill; greedy algorithms tend to be easier to code
  • 14. Coin Change With Dynamic Programming  Make a change, Total = 6  Available Coin Set = { 2, 3, 5 } T[i] [j] is the 2D array to denote the minimum number of coins require to make the change Coin[i] is the sorted array of available coin sets. [Index Start from 1]  If V == 0, then 0 coins required. T[i][j] = 0  If V > 0 Case 1: T [i][j] = T [i-1][j] If Coin[i] is not takes Case 2: T [i][j] = 1 + T [i] [j–Coin [i]] If Coin[ i ] is taken
  • 15. T [i][j] = MIN ( T [i-1][j] , 1 + T[i][j-Coin[i] ) 0 1 2 3 4 5 6 2 3 5 0 0 0 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 1 ∞ 2 ∞ 3 ∞ ∞ 1 1 2 1 2 1 1 2 2 2
  • 16. Result:  Number of Coins requires to make a change to 6 = 2  Coin Set = { 3, 3 }
  翻译: