
- Data Structures & Algorithms
- DSA - Home
- DSA - Overview
- DSA - Environment Setup
- Algorithm
- DSA - Algorithms Basics
- DSA - Asymptotic Analysis
- DSA - Greedy Algorithms
- DSA - Divide and Conquer
- DSA - Dynamic Programming
- Data Structures
- DSA - Data Structure Basics
- DSA - Data Structures and Types
- DSA - Array Data Structure
- Linked Lists
- DSA - Linked List Basics
- DSA - Doubly Linked List
- DSA - Circular Linked List
- Stack & Queue
- DSA - Stack
- DSA - Expression Parsing
- DSA - Queue
- Searching Techniques
- DSA - Linear Search
- DSA - Binary Search
- DSA - Interpolation Search
- DSA - Hash Table
- Sorting Techniques
- DSA - Sorting Algorithms
- DSA - Bubble Sort
- DSA - Insertion Sort
- DSA - Selection Sort
- DSA - Merge Sort
- DSA - Shell Sort
- DSA - Quick Sort
- Graph Data Structure
- DSA - Graph Data Structure
- DSA - Depth First Traversal
- DSA - Breadth First Traversal
- Tree Data Structure
- DSA - Tree Data Structure
- DSA - Tree Traversal
- DSA - Binary Search Tree
- DSA - AVL Tree
- DSA - Red Black Trees
- DSA - B Trees
- DSA - B+ Trees
- DSA - Splay Trees
- DSA - Spanning Tree
- DSA - Tries
- DSA - Heap
- Recursion
- DSA - Recursion Basics
- DSA - Tower of Hanoi
- DSA - Fibonacci Series
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Minimum number of coins that make a given value
There is a list of coin C(c1, c2, ……Cn) is given and a value V is also given. Now the problem is to use the minimum number of coins to make the chance V.
Note: Assume there is the infinite number of coins C.
In this problem, we will consider a set of different coins C{1, 2, 5, 10} are given, There is the infinite number of coins of each type. To make change the requested value we will try to take the minimum number of coins of any type. As an example, for value 22: we will choose {10, 10, 2}, 3 coins as the minimum.
Input and Output
Input: The required value. Say 48 Output: Minimum required coins. Here the output is 7. 48 = 10 + 10 + 10 + 10 + 5 + 2 + 1
Algorithm
minCoins(coinList, n, value)
Input: list of different coins, number of coins, given value.
Output: Minimum number of coins to get given value.
Begin if value = 0, then return 0 define coins array of size value + 1, fill with ∞ coins[0] := 0 for i := 1 to value, do for j := 0 to n, do if coinList[j] <= i, then tempCoins := coins[i-coinList[j]] if tempCoins ≠ ∞ and (tempCoins + 1) < coins[i], then coins[i] := tempCoins + 1 done done return coins[value] End
Example
#include<iostream> using namespace std; int minCoins(int coinList[], int n, int value) { int coins[value+1]; //store minimum coins for value i if(value == 0) return 0; //for value 0, it needs 0 coin coins[0] = 0; for (int i=1; i<=value; i++) coins[i] = INT_MAX; //initially all values are infinity except 0 value for (int i=1; i<=value; i++) { //for all values 1 to value, find minimum values for (int j=0; j<n; j++) if (coinList[j] <= i) { int tempCoins = coins[i-coinList[j]]; if (tempCoins != INT_MAX && tempCoins + 1 < coins[i]) coins[i] = tempCoins + 1; } } return coins[value]; //number of coins for value } int main() { int coins[] = {1, 2, 5, 10}; int n = 4, value; cout << "Enter Value: "; cin >> value; cout << "Minimum "<<minCoins(coins, n, value)<<" coins required."; return 0; }
Output
Enter Value: 48 Minimum 7 coins required.
- Related Articles
- Golang program to find the minimum number of coins needed to make a given amount of money
- Program to find number of coins needed to make the changes with given set of coins in Python
- Minimum number of given operations required to make two strings equal using C++.
- Minimum number of flipping adjacent bits required to make given Binary Strings equal
- C/C++ Program for Greedy Algorithm to find Minimum number of Coins
- Minimum number of given moves required to make N divisible by 25 using C++.
- C++ program to count number of minimum coins needed to get sum k
- Minimum number of swaps required such that a given substring consists of exactly K 1s
- Minimum number using set bits of a given number in C++
- Find out the minimum number of coins required to pay total amount in C++
- Minimum number of deletions to make a string palindrome in C++.
- Program to find number of coins needed to make the changes in Python
- Minimum number of elements that should be removed to make the array good using C++.
- I have a total of rupees 300 in coins of denomination rupees 1, 2, 5 the number of rupees 2 coins is 3 times the number of rupees 5 coins. The total number of coins is 160. Find the number of coins of each denomination.
- Minimum number of Appends needed to make a string palindrome in C++

Advertisements