SlideShare a Scribd company logo
2
Most read
6
Most read
7
Most read
TOPIC : COIN CHANGING
(DP & GREEDY)
WELCOME TO THE PRESENTATION
THINGS TO BE EXPLAINED:
 DP & Greedy
 Definition Of Coin Changing
 Example with explanation
 Time complexity
 Difference between DP & Greedy in Coin
Change Problem
DP : DYNAMIC PROGRAMMING
 Dynamic programming is a method for solving a complex
problem by breaking it down into a collection of simpler sub
problems just once and storing their solutions.
 DP is used to solve problems with the following characteristics :
Simple Sub problems
Optimal Structure Of The Problems
Overlapping Sub problems
GREEDY ALGORITHM
A greedy algorithm always makes the choice that looks best
at the moment. It makes a locally optimal choice in the hope
that this choice will lead to a globally optimal solution.
An algorithm is greedy if it builds a solution in small steps,
choosing a decision at each step locally , not considering what
happen ahead to optimize some underlying criterion
COIN CHANGE PROBLEM
Coin change is the problem of finding the minimum number
of ways of making changes for a particular amount of taka,
using a given unlimited amounts of coins. It is a general case
of Integer Partition.
D[1] = C[P – D[1]] + 1; here D[1] = 1;
= C[6 – 1 ] +1;
= C[5] +1 ;
= 5 +1;
= 6
MINIMUM
NUMBER
OF COINS
EXAMPLE:
Set Of Coins, D = { 1,5,6,9 }
Make Change Of Taka, n = 11
0 1 2 3 4 1 1 2 3 1 2 3
1 1 1 1 5 6 1 1 9 5
C[P] =
S[P] =
0 1 2 3 4 5 6 7 8 9 10 11 P
5
2
50 6
For P=6;
D[2] = C[P – D[1]] + 1; here D[2] = 5;
= C[6 – 5 ] +1;
= C[1] +1 ;
= 1+1;
= 2
D[3] = C[P – D[1]] + 1; here D[3] = 6;
= C[6 – 6] +1;
= C[0] +1 ;
= 0 +1;
= 1
0, if P = 0
min ( C[P-D[i]] + 1 ), if P > 0
D[1] <= D[i] <=P
C[P] =
EXPLANATION OF COIN CHANGE (DP) :
C[P] =
TIME COMPLEXITY:
Time Complexity = O(m*n), where m = Total taka & n = Number of coin
 If D is unsorted , then sort D in Ascending Order
 Take two array C[P] and S[P] where,
C[P] = Minimum number of coins used for P Tk
S[P] = Last coin used to make P Tk.
 Fill the C[P] and S[P] tables
 Find C[P] using the following equation,
0, if P = 0
min ( C[P-D[i]] + 1 ), if P > 0
D[1] <= D[i] <=P
EXAMPLE:
Set Of Coins, D = {9,6,5,1}
Make Change Of Taka, n = 11
3. 2 / 6 =
2. 11 % 9 = 2
1. 11 / 9 =
5. 2 / 5 =
4. 2 % 6 = 2
6. 2 % 5 = 2
7. 2 / 1 =
8. 2 % 1 = 0
1
0
0
2
TAKEN COIN :
9(1) & 1(2)
 If D is unsorted, then sort D in descending order.
 Find the taken coin and their minimum number using the following algorithm
for(D[1] to D[n] )
{
result = n/D[i];
n = n (mod) D[i];
if(result = 0)
print result and D[i]
}
 Repeat for each coin
EXPLANATION OF COIN CHANGE (GREEDY):
TIME COMPLEXITY:
Time complexity = O(n), where n = Number of coin
 Set Of Coins, D = {1,5,6,9}
 Make Change Of Taka, n = 11
o Result :
Minimum Number of coin : 2.
The coins : 5, 6.
 Set Of Coins, D = {1,5,8,10}
 Make Change Of Taka, n = 15
o Result :
Minimum Number of coin : 2.
The coins : 10, 5.
 Set Of Coins, D = {9,6,5,1}
 Make Change Of Taka, n = 11
o Result :
Minimum Number of coin : 3.
The coins : 9(1), 1(2).
 Set Of Coins, D = {10,8,5,1}
 Make Change Of Taka, n = 15
o Result :
Minimum Number of coin : 2.
The coins : 10(1), 5(1).
THANK YOU
ANY QUESTIONS ??

More Related Content

PPTX
Gender sensitization
PPTX
Coin Change : Greedy vs Dynamic Programming
PPTX
Introduction to Pseudocode
PPTX
PDF
21st century skills
PPTX
Heap sort
PPTX
Regular expressions in Python
PPT
Coordination chemistry - CFT
Gender sensitization
Coin Change : Greedy vs Dynamic Programming
Introduction to Pseudocode
21st century skills
Heap sort
Regular expressions in Python
Coordination chemistry - CFT

What's hot (20)

PDF
Coin Change Problem
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
Asymptotic Notation
PPTX
Job sequencing with deadline
PPT
SINGLE-SOURCE SHORTEST PATHS
PPTX
Bellman ford Algorithm
PPT
Bellman Ford's Algorithm
PPTX
Travelling salesman dynamic programming
PPT
Time complexity
PPTX
sum of subset problem using Backtracking
PPTX
Knapsack Problem
DOC
Time and space complexity
PPTX
Greedy Algorithm - Knapsack Problem
PDF
P, NP, NP-Complete, and NP-Hard
PPTX
Brute force method
PPTX
heap Sort Algorithm
PPTX
CLR AND LALR PARSER
PPT
Master method theorem
PPTX
Strassen's matrix multiplication
PPTX
Greedy algorithms
Coin Change Problem
Algorithms Lecture 2: Analysis of Algorithms I
Asymptotic Notation
Job sequencing with deadline
SINGLE-SOURCE SHORTEST PATHS
Bellman ford Algorithm
Bellman Ford's Algorithm
Travelling salesman dynamic programming
Time complexity
sum of subset problem using Backtracking
Knapsack Problem
Time and space complexity
Greedy Algorithm - Knapsack Problem
P, NP, NP-Complete, and NP-Hard
Brute force method
heap Sort Algorithm
CLR AND LALR PARSER
Master method theorem
Strassen's matrix multiplication
Greedy algorithms
Ad

Similar to Coin change Problem (DP & GREEDY) (20)

PDF
Microsoft Word Hw#3
PDF
1ST_UNIT_DAdefewfrewfgrwefrAdfdgfdsgevedr (2).pdf
PDF
Daa chapter 3
PPTX
K means clustering
PDF
Unit-1 DAA_Notes.pdf
PPT
dynamic-programming unit 3 power point presentation
PPT
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
PPTX
dynamic programming complete by Mumtaz Ali (03154103173)
PDF
Digital electronics k map comparators and their function
PPT
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
PDF
Analysis of Electro-Mechanical System
PDF
Introduction to Polyhedral Compilation
PDF
Rsa documentation
DOC
algorithm Unit 3
PPTX
01 - DAA - PPT.pptx
PPT
Algorithm And analysis Lecture 03& 04-time complexity.
DOCX
Unit 7 dynamic programming
PDF
DRL challenge on Montezuma's Revenge
PPTX
Introducing maths in qbasic
PPTX
Test s velocity_15_5_4
Microsoft Word Hw#3
1ST_UNIT_DAdefewfrewfgrwefrAdfdgfdsgevedr (2).pdf
Daa chapter 3
K means clustering
Unit-1 DAA_Notes.pdf
dynamic-programming unit 3 power point presentation
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
dynamic programming complete by Mumtaz Ali (03154103173)
Digital electronics k map comparators and their function
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
Analysis of Electro-Mechanical System
Introduction to Polyhedral Compilation
Rsa documentation
algorithm Unit 3
01 - DAA - PPT.pptx
Algorithm And analysis Lecture 03& 04-time complexity.
Unit 7 dynamic programming
DRL challenge on Montezuma's Revenge
Introducing maths in qbasic
Test s velocity_15_5_4
Ad

Recently uploaded (20)

PPTX
Learning-Plan-5-Policies-and-Practices.pptx
PPTX
nose tajweed for the arabic alphabets for the responsive
PPTX
worship songs, in any order, compilation
PPTX
Tour Presentation Educational Activity.pptx
PPTX
Hydrogel Based delivery Cancer Treatment
PPTX
Primary and secondary sources, and history
PPTX
lesson6-211001025531lesson plan ppt.pptx
PPT
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
Tablets And Capsule Preformulation Of Paracetamol
PPTX
Intro to ISO 9001 2015.pptx wareness raising
PDF
natwest.pdf company description and business model
PPTX
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
PPTX
S. Anis Al Habsyi & Nada Shobah - Klasifikasi Hambatan Depresi.pptx
PPTX
water for all cao bang - a charity project
PPTX
Self management and self evaluation presentation
PDF
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
PPTX
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
PPTX
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PDF
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf
Learning-Plan-5-Policies-and-Practices.pptx
nose tajweed for the arabic alphabets for the responsive
worship songs, in any order, compilation
Tour Presentation Educational Activity.pptx
Hydrogel Based delivery Cancer Treatment
Primary and secondary sources, and history
lesson6-211001025531lesson plan ppt.pptx
The Effect of Human Resource Management Practice on Organizational Performanc...
Tablets And Capsule Preformulation Of Paracetamol
Intro to ISO 9001 2015.pptx wareness raising
natwest.pdf company description and business model
INTERNATIONAL LABOUR ORAGNISATION PPT ON SOCIAL SCIENCE
S. Anis Al Habsyi & Nada Shobah - Klasifikasi Hambatan Depresi.pptx
water for all cao bang - a charity project
Self management and self evaluation presentation
Tunisia's Founding Father(s) Pitch-Deck 2022.pdf
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
Nykaa-Strategy-Case-Fixing-Retention-UX-and-D2C-Engagement (1).pdf

Coin change Problem (DP & GREEDY)

  • 1. TOPIC : COIN CHANGING (DP & GREEDY) WELCOME TO THE PRESENTATION
  • 2. THINGS TO BE EXPLAINED:  DP & Greedy  Definition Of Coin Changing  Example with explanation  Time complexity  Difference between DP & Greedy in Coin Change Problem
  • 3. DP : DYNAMIC PROGRAMMING  Dynamic programming is a method for solving a complex problem by breaking it down into a collection of simpler sub problems just once and storing their solutions.  DP is used to solve problems with the following characteristics : Simple Sub problems Optimal Structure Of The Problems Overlapping Sub problems
  • 4. GREEDY ALGORITHM A greedy algorithm always makes the choice that looks best at the moment. It makes a locally optimal choice in the hope that this choice will lead to a globally optimal solution. An algorithm is greedy if it builds a solution in small steps, choosing a decision at each step locally , not considering what happen ahead to optimize some underlying criterion
  • 5. COIN CHANGE PROBLEM Coin change is the problem of finding the minimum number of ways of making changes for a particular amount of taka, using a given unlimited amounts of coins. It is a general case of Integer Partition.
  • 6. D[1] = C[P – D[1]] + 1; here D[1] = 1; = C[6 – 1 ] +1; = C[5] +1 ; = 5 +1; = 6 MINIMUM NUMBER OF COINS EXAMPLE: Set Of Coins, D = { 1,5,6,9 } Make Change Of Taka, n = 11 0 1 2 3 4 1 1 2 3 1 2 3 1 1 1 1 5 6 1 1 9 5 C[P] = S[P] = 0 1 2 3 4 5 6 7 8 9 10 11 P 5 2 50 6 For P=6; D[2] = C[P – D[1]] + 1; here D[2] = 5; = C[6 – 5 ] +1; = C[1] +1 ; = 1+1; = 2 D[3] = C[P – D[1]] + 1; here D[3] = 6; = C[6 – 6] +1; = C[0] +1 ; = 0 +1; = 1 0, if P = 0 min ( C[P-D[i]] + 1 ), if P > 0 D[1] <= D[i] <=P C[P] =
  • 7. EXPLANATION OF COIN CHANGE (DP) : C[P] = TIME COMPLEXITY: Time Complexity = O(m*n), where m = Total taka & n = Number of coin  If D is unsorted , then sort D in Ascending Order  Take two array C[P] and S[P] where, C[P] = Minimum number of coins used for P Tk S[P] = Last coin used to make P Tk.  Fill the C[P] and S[P] tables  Find C[P] using the following equation, 0, if P = 0 min ( C[P-D[i]] + 1 ), if P > 0 D[1] <= D[i] <=P
  • 8. EXAMPLE: Set Of Coins, D = {9,6,5,1} Make Change Of Taka, n = 11 3. 2 / 6 = 2. 11 % 9 = 2 1. 11 / 9 = 5. 2 / 5 = 4. 2 % 6 = 2 6. 2 % 5 = 2 7. 2 / 1 = 8. 2 % 1 = 0 1 0 0 2 TAKEN COIN : 9(1) & 1(2)
  • 9.  If D is unsorted, then sort D in descending order.  Find the taken coin and their minimum number using the following algorithm for(D[1] to D[n] ) { result = n/D[i]; n = n (mod) D[i]; if(result = 0) print result and D[i] }  Repeat for each coin EXPLANATION OF COIN CHANGE (GREEDY): TIME COMPLEXITY: Time complexity = O(n), where n = Number of coin
  • 10.  Set Of Coins, D = {1,5,6,9}  Make Change Of Taka, n = 11 o Result : Minimum Number of coin : 2. The coins : 5, 6.  Set Of Coins, D = {1,5,8,10}  Make Change Of Taka, n = 15 o Result : Minimum Number of coin : 2. The coins : 10, 5.  Set Of Coins, D = {9,6,5,1}  Make Change Of Taka, n = 11 o Result : Minimum Number of coin : 3. The coins : 9(1), 1(2).  Set Of Coins, D = {10,8,5,1}  Make Change Of Taka, n = 15 o Result : Minimum Number of coin : 2. The coins : 10(1), 5(1).