A dynamic-programming state is a precisely defined subproblem: its meaning tells you what answer a table entry represents, while its parameters identify which subproblem it is. A recurrence is a separate rule for computing that answer from other states. In an interview, make the state explicit before presenting the recurrence, then give the base cases, computation order, final answer, and complexity.
What a DP state means
Writing dp[i] does not define a state. You must say what dp[i] represents in plain language. For example, it might be the best score obtainable from position i to the end of a sequence, or the number of ways to reach a particular position. The index identifies a subproblem; the sentence supplies its meaning.
As an Amazon Associate I earn from qualifying purchases.
MIT OpenCourseWare’s Lecture 15 on dynamic programming recommends describing a subproblem in words and in terms of its parameters. Common sequence subproblems concern prefixes, suffixes, or contiguous substrings. Other problems use such parameters as a grid coordinate, a graph vertex, or a remaining resource limit.
The state definition is a semantic contract: every value stored at a state must answer the question promised by that definition. The recurrence is valid only if it computes that answer from correctly defined related subproblems.
Choose parameters that preserve the information the future needs
A state needs enough information to distinguish subproblems whose valid next choices or answers differ. Suppose a problem processes items subject to a capacity limit. An index alone may not suffice: two paths reaching the same item position with different remaining capacities can have different options. A state such as dp[i][capacity] can represent the subproblem involving both a prefix position and a capacity value.
Too few parameters merge distinct subproblems and can make a recurrence incorrect. Too many parameters create unnecessary states, increasing storage and often computation. A useful interview test is to ask: if two partial solutions have the same proposed state, do they really have the same remaining problem and the same valid transitions?
Rank #2
Separate the state from the recurrence
After defining what a state means, derive how its answer follows from choices or predecessor states. The recurrence is that computation rule; it is not the state definition. For example, defining F[i] as the ith Fibonacci number establishes the state. The rule F[i] = F[i - 1] + F[i - 2] establishes how to compute it for later indices.
Free tools Windows power users keep installed
One-click scans. No signup required.
This distinction matters when checking correctness. First ask whether each state describes the intended subproblem. Then ask whether the recurrence considers the relevant choices and produces the correct value for that subproblem. MIT’s lecture treats defining subproblems and relating their solutions recursively as distinct steps.
Examples that make state semantics concrete
Fibonacci numbers
Let F[i] mean the ith Fibonacci number. The first two values are base cases; for subsequent indices, F[i] = F[i - 1] + F[i - 2]. Computing indices in increasing order respects those dependencies, and the requested result is F[n]. The University of Texas at Austin’s Lecture 11 on dynamic programming contrasts repeated recursive work with memoization and describes storing a linear number of values for memoized Fibonacci. Its time analysis counts arithmetic operations under a unit-cost integer model; for very large integers, the cost of the arithmetic itself also grows.
Shortest paths in a directed acyclic graph
For a directed acyclic graph with source s, define the state for vertex v as the distance from s to v. The source has distance zero. For another vertex, the recurrence takes the minimum of the distance to each incoming predecessor plus the weight of that predecessor’s edge into v. A topological ordering ensures each predecessor is handled before its dependent vertex. This example shows that a state can be identified by a graph vertex rather than an array index. MIT OpenCourseWare gives a running time of O(|V| + |E|) for this DAG shortest-path method.
Rank #4
A suffix state for bowling
MIT’s bowling example defines B(i) as the best score obtainable from pin i through the end. At a position, the available choices include skipping a pin, taking one pin, or taking two adjacent pins; each choice leads to a smaller suffix subproblem. The state captures the remaining portion of the sequence, and the choices determine the recurrence. MIT analyzes this formulation as having Θ(n) subproblems and Θ(1) work per subproblem, for Θ(n) total time under memoization.
A reliable interview workflow
- Check whether dynamic programming fits. Look for overlapping subproblems and a way to combine their answers into the larger problem. Optimization or counting language can be a clue, but it is not proof. The University of Texas at Austin lecture describes DP as eliminating redundancy in repeated work.
- Define the subproblem in words. State exactly what one value represents, then list the parameters that distinguish one subproblem from another.
- Derive the recurrence. Identify the choices or predecessor states that determine the current answer. Test the rule on a tiny example to expose missing cases or invalid transitions.
- Give base cases and a valid evaluation method. In a bottom-up solution, explain the order that places dependencies before the states that use them. In a top-down solution, explain how recursion and caching handle those dependencies.
- Connect the states to the requested result. The answer may be one cell, such as
dp[n], or an aggregate over several states. If the task asks for an actual path or set of choices—not just its score—store enough parent or choice information to reconstruct it. - Analyze time and space. Count reachable states and the work done per state. Explain what values must be stored, and describe any space reduction only after identifying which previous values the recurrence needs.
- Present the model before coding. Saying the state and recurrence first lets the interviewer check what the solution means and which assumptions its transitions rely on.
Choosing between state formulations and implementation styles
When two formulations seem plausible, compare their semantic clarity, whether they contain all information that affects future choices, how many states are reachable, and the work required for each transition. Also consider whether the dependency order is easy to justify, whether memory or recursion depth is a concern, and whether the problem requires reconstructing a solution.
Top-down memoization follows recursive dependencies and can avoid evaluating states that are never needed. Bottom-up tabulation avoids recursion depth and can make a rolling-array optimization straightforward. Neither style is automatically better; the problem’s dependencies, reachable states, and implementation constraints decide the trade-off.
The overall design sequence is consistent: define subproblems, relate them recursively, establish an acyclic dependency order, identify base cases, extract the original answer, and analyze the work. A clear state makes every later step easier to inspect.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →




