Recursive Algorithm Time Complexity Coin Change
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
The recursive coin-change problem is a classic example of how an elegant-looking algorithm can hide a very expensive time complexity. The recursive version repeatedly explores the same subproblems, which makes it a useful teaching example for why memoization and dynamic programming matter.
The exact complexity depends on which coin-change variant you mean, but the common naive recursive approach is exponential. That is the key result most people are trying to understand when they ask about coin-change recursion.
The Naive Recursive Version
Suppose you want the minimum number of coins needed to make a target amount. A straightforward recursive function tries every coin and recursively solves the smaller remaining amount.
This code is correct for small inputs, but it recomputes the same amounts again and again. For example, if the function evaluates amount 6, it may reach amount 3 through several different paths and solve it from scratch every time.
Why the Time Complexity Blows Up
At each amount, the function branches across all coin choices. If there are n coin denominations and the recursion can go as deep as the target amount A, the recursion tree can grow roughly like n^A in the worst case.
That is not a tight mathematical bound for every coin system, but it captures the important truth: the naive recursion is exponential. The repeated subproblems are what make it so expensive.
You can see the overlap with a tiny example:
- '
min_coins(6)may callmin_coins(5),min_coins(3), andmin_coins(2)' - '
min_coins(5)may also callmin_coins(4),min_coins(2), andmin_coins(1)' - '
min_coins(3)may callmin_coins(2)again'
The amount 2 appears repeatedly. The recursive algorithm treats each appearance as a new problem even though the answer is identical every time.
Memoization Changes the Cost Completely
Once you cache the answer for each amount, every subproblem is solved once instead of many times.
Now there are only A + 1 meaningful subproblems, from 0 through A. For each amount, you try n coins. That makes the time complexity O(A * n) and the memo size O(A).
Bottom-Up Dynamic Programming
The same complexity can be reached iteratively with bottom-up dynamic programming:
This avoids recursion depth concerns and is usually the practical implementation for production code.
Common Pitfalls
- Calling the naive recursion "polynomial" because each call looks small. The branching tree makes it exponential.
- Ignoring overlapping subproblems. That is the whole reason memoization helps so much.
- Confusing the minimum-coins problem with the number-of-ways problem. They are related but not identical and use different recurrences.
- Forgetting the base cases for
0and negative amounts, which breaks correctness. - Using pure recursion on large amounts in Python, which can also run into recursion-depth limits.
Summary
- The naive recursive coin-change algorithm is exponential because it recomputes the same amounts many times.
- A rough worst-case intuition is that the recursion tree grows like
n^A, wherenis the number of coin types andAis the amount. - Memoization reduces the complexity to
O(A * n). - Bottom-up dynamic programming reaches the same complexity without recursion.
- Coin change is a standard example of overlapping subproblems and why dynamic programming works.
Related reading
- Recursive Karatsuba multiplication not working?
- recursive query for adjacency list to preorder tree traversal in SQL?
- Recursively counting files in a Linux directory
- Recursively iterate through all subdirectories using pathlib
- Redis - Benchmark vs reality
- Redis / RabbitMQ - Pub / Sub - Performances
- Recursively list files in Java
- Recursively print all permutations of a string Javascript

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.