Dynamic Programming
Last updated
Was this helpful?
Last updated
Was this helpful?
Define the objective function. Function you want to minimize or maximize in your problem.
Identify base cases. These are the boundaries of the problem — the starting point of your DP algorithm.
Write down the transition function (recurrence relation). Function to transit from one subproblem to another subproblem. Takes the system from one state to another.
Identify the order of execution. Order in which subproblems are solved.
Identify the location of the answer. For example, F(n) or F(0).
Bottom-Up (Tabulation). Iterative.
Top-Down (Memoization). Recursive.