- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to implement coin change problem using bottom-up approach using C#?
CoinChangeBottomUpApproach takes 3 parameters as input n is the amount, coins array contains the total number of coins, t contains total number of coins. Declare a dynamic array which stores the previously calculated values. loop through the array and calculate the minimum coins required to calculate the amount. If the calculation is already done the take the value from the dynamic array.
Time complexity − O(N)
Space complexity − O(N)
Example
public class DynamicProgramming{ public int CoinChangeBottomUpApproach(int n,int[] coins,int t){ int[] dp = new int[100]; for (int i = 1; i < n; i++){ dp[i] = int.MaxValue; for (int j = 0; j < t; j++){ if (i - coins[j] >= 0){ int subProb = dp[i - coins[j]]; dp[i] = Math.Min(dp[i], subProb + 1); } } } return dp[n]+1; } } static void Main(string[] args){ DynamicProgramming dp = new DynamicProgramming(); int[] coins = { 1, 7, 10 }; int ss = dp.CoinChangeBottomUpApproach(15, coins, coins.Count()); Console.WriteLine(ss); }
Output
3
- Related Articles
- How to implement coin change problem using topDown approach using C#?
- How to implement Fibonacci using bottom-up approach using C#?
- How to implement minimum step to one using bottom-up approach using C#?
- How to implement Fibonacci using topDown approach using C#?
- Minimum Coin Change Problem
- How to implement minimum step to one using topDown approach using C#?
- Python Program to Find Longest Common Substring using Dynamic Programming with Bottom-Up Approach
- Difference Between Top-down and Bottom-up Approach
- C++ Program to Implement Traveling Salesman Problem using Nearest Neighbour Algorithm
- fork() to execute processes from bottom to up using wait() in C++
- C Program Coin Change
- C++ Program to Implement Network_Flow Problem
- Coin Change 2 in C++
- How to implement Single Responsibility Principle using C#?
- How to implement Open Closed principle using C#?

Advertisements