Dynamic Programming Patterns

Classic problems solved with dynamic programming.

  • JSON4,251 B
  • YAML3,082 B · −27%
  • TOON2,580 B · −39%

Classic dynamic-programming problems: Fibonacci, 0/1 knapsack, longest common subsequence, longest increasing subsequence, coin change, matrix chain multiplication, edit distance and maximum subarray, extended with rod cutting, longest palindromic subsequence, partition, house robber, word break, unique paths and egg dropping.

Use it when

  • You need a canonical problem for a DP pattern such as a 1D, 2D or interval recurrence.
  • You are practicing recognizing overlapping subproblems.

Watch out for

  • DP needs optimal substructure and overlapping subproblems; check both before applying it.
  • Table size can dominate memory; space optimizations often keep only the previous row.

The data

ProblemDescription
FibonacciCompute nth Fibonacci using memoization or tabulation.
0/1 KnapsackSelect items to maximize value without exceeding capacity.
Longest Common SubsequenceFind longest subsequence present in two sequences.
Longest Increasing SubsequenceFind longest strictly increasing subsequence.
Coin ChangeMinimum coins needed to make a target amount.
Matrix Chain MultiplicationOptimal parenthesization for multiplying matrices.
Edit DistanceMinimum operations to convert one string to another.
Maximum SubarrayContiguous subarray with the largest sum.
Rod CuttingCut a rod into pieces to maximize total price given a price for each length.
Longest Palindromic SubsequenceFind the longest subsequence of a string that reads the same in both directions.
Partition ProblemDecide whether a set can be split into two subsets with equal sums.
House RobberMaximize the loot from a row of houses without taking two adjacent houses.
Word BreakDecide whether a string can be segmented into words from a dictionary.
Unique PathsCount the paths from the top-left to the bottom-right of a grid moving only right or down.
Egg DroppingFind the minimum number of trials needed to determine the highest safe floor with a given number of eggs.

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
dataproblemstringFibonacci
datadescriptionstringCompute nth Fibonacci using memoization or tabu…

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/dynamic-programming-patterns?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/dynamic-programming-patterns.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • algorithms
  • dynamic-programming
  • optimization

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets