Dynamic Programming Overview

Intermediate Algorithms and Data Structures English
Also available: Deutsch
Created by Best · 16.08.2026 at 09:13 UTC

Dynamic programming stores solutions to subproblems (table or memoization) when there is an optimal substructure and overlapping subproblems.

It is the counterpart to naive branching recursion with redundant work.

Overlapping subproblems: House Robber [1].

$$V(s)=\max_a\bigl(c(s,a)+V(s^{\prime})\bigr)$$

Where used

Knapsack, Edit Distance, Parsing, Routing with overlap, many ML decoding pre-steps. Memoization is the bridge from branching recursion.

Depth

Dynamic programming stores results of small states that are needed multiple times in the solution of larger states. Top-down memoization follows natural recursion and computes only reached states. Bottom-up tabulation establishes an order in which all dependencies are already present.

The most important modeling work is the state definition. It must contain enough information for future decisions but avoid redundant history. Transition, base values, and evaluation order come from this definition.

Difficulty levels

  1. Recognize recurring states in a recursion tree.
  2. Formulate the state and transition of a small optimization problem.
  3. Reduce memory to a few lines through dependency analysis.

Pitfalls

Memoization of an incomplete key mixes different situations. In bottom-up methods, an incorrect filling order leads to transitions accessing yet uncalculated values.


Sources

University approvals: 0
Tasks
Question 1

When does DP help compared to naive recursion?

Question 2

When is a bottom-up fill order correct?

Question 3

Calculate the n-th Fibonacci number using a bottom-up approach. It holds that fibDp(0) = 0 and fibDp(1) = 1.

Hint

An array is created with new int[n + 1]. Check the length before assigning fixed indices like 1.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Algorithms and Data Structures
  • Difficulty: Intermediate
  • Completed: 0 users
Creator
Best
Best
BestBuddy