Algorithm Visualizer

Coin Change Algorithms

Greedy · Dynamic Programming · Hybrid

Configuration
Greedy
coins used
Dynamic Programming
coins used
Hybrid (min of both)
coins used
Step-by-step Trace
Greedy Steps
Run the algorithm to see steps.
DP Optimal Steps
Run the algorithm to see steps.
DP Table
Time & Space Complexity
Greedy
Sort O(n²) bubble sort on n coins
Selection O(n · A) n coins × amount A
Total Time O(n² + n·A)
Space O(1) in-place, no extra array
⚠ Not always optimal
Dynamic Programming
Fill DP table O(n · A) n coins × amount A
Trace back O(A) reconstruct solution
Total Time O(n · A)
Space O(A) dp[ ] array of size A+1
✔ Always optimal
Hybrid
Runs both Greedy + DP then picks minimum
Total Time O(n · A) DP dominates
Space O(A) from DP table
✔ Always optimal result
n = number of coin denominations A = target amount