CSAlgorithms & ComplexityDiagramIntermediate
Dynamic Programming
KO: 동적 계획법 (DP)·EN: Dynamic Programming·JA: 動的計画法(DP)·DP
An optimization technique that breaks complex problems into overlapping subproblems and caches their results to avoid redundant exponential recomputation
Table of Contents
Structure Diagram
Dynamic Programming Overlapping Subproblem MemoizationTap a node
RESULTdp[5] (Result)
2 linksQuick Answer
What is Dynamic Programming?
An optimization technique that breaks complex problems into overlapping subproblems and caches their results to avoid redundant exponential recomputation. It is a core concept in Algorithms & Complexity within CS.
Core Principles
Dynamic Programming (DP) eliminates redundant exponential work whenever a problem exhibits two properties:
- Overlapping Subproblems: The same sub-computations recur repeatedly.
- Optimal Substructure: Optimal solutions to subproblems combine into an optimal global solution.
DP is implemented either Top-Down (Memoization)—adding a cache to recursion—or Bottom-Up (Tabulation)—filling a table iteratively from base cases.
Practical Takeaways
- Define state before coding: Clearly state what
dp[i][j]represents, write the recurrence transition, and verify base cases. - Compress space with rolling arrays: If row
ionly depends on rowi-1, reduceO(N·M)memory down toO(M). - Prefer Bottom-Up for deep states: Iterative tabulation avoids recursion-depth stack overflows and reduces function-call overhead.
Notable Examples
- Git Diff & Spellcheck: Longest Common Subsequence (LCS) and Levenshtein Edit Distance.
- SQL Query Optimizers: Choosing optimal multi-table join orders via DP.
- Viterbi Decoding & Resource Allocation: Speech/NLP sequence decoding and Knapsack-style budget optimization.