Skip to main content
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
stepstepreusereuseO(1) lookuO(1) lookudp[5] (Re…dp[4] cac…dp[3] reu…dp[2]dp[1] base
RESULTdp[5] (Result)
2 links
Quick 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:

  1. Overlapping Subproblems: The same sub-computations recur repeatedly.
  2. 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 i only depends on row i-1, reduce O(N·M) memory down to O(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.