Tabulation solves the smallest subproblems first and fills a table with loops, with no recursion. Each cell depends only on cells already filled. It avoids stack depth limits and usually runs faster than memoization. In minimum coin change, dp[a] is the fewest coins for amount a, computed as min(dp[a - coin] + 1) over coins that fit.
Remember
dp[0] = 0;
for (a = 1; a <= amount; a++) {
dp[a] = INF;
for each coin c: if (c <= a && dp[a - c] + 1 < dp[a]) dp[a] = dp[a - c] + 1;
}
Reference
Cheat Sheet
Keep these facts handy while you work with Tabulation (Bottom-Up DP) in C in C.
#include <stdio.h>
#define INF 99
int main(void) {
int coins[] = {1, 3, 4};
int amount = 6, dp[7];
dp[0] = 0;
for (int a = 1; a <= amount; a++) {
dp[a] = INF;
for (int i = 0; i < 3; i++)
if (coins[i] <= a && dp[a - coins[i]] + 1 < dp[a])
dp[a] = dp[a - coins[i]] + 1;
}
printf("dp:");
for (int a = 0; a <= amount; a++) printf(" %d", dp[a]);
printf("\nminimum coins for %d: %d\n", amount, dp[amount]);
return 0;
}
Output
dp: 0 1 2 1 1 2 2
minimum coins for 6: 2
How It Works
dp[3] and dp[4] are 1 because those are coin values.
dp[6] uses dp[3] + 1 = 2, meaning 3 + 3.
Greedy would pick 4 + 1 + 1 = 3 coins, so tabulation beats greedy here.
Edge Cases & Pitfalls
Check these before relying on Tabulation (Bottom-Up DP) in C in real programs.
inf
Overflow with INF
Adding 1 to a huge INF can overflow; use a moderate value or check first.
init
Uninitialized cells
Every cell must be set before it is read.
Remember
Key Takeaways
Fill small to large.
No recursion.
Cell = best of smaller cells.
One line: Tabulation solves the smallest subproblems first and fills a table with loops, with no recursion.
Frequently Asked Questions
A bottom-up approach that iteratively fills a table of subproblem answers starting from the base cases.
Tabulation avoids recursion overhead and stack limits; memoization only computes the states that are actually needed.
Continue with "Two-Pointer Technique in C" next. Find a pair in a sorted array and remove duplicates in place. The C Algorithm Techniques hub lists every topic in order.