BeginnerTopic 29 of 104Software & Computing

Dynamic programming

Solves overlapping subproblems once and stores results.

In depth

DP solves problems with overlapping subproblems and optimal substructure by storing sub-results (memoisation or tabulation). Classics: Fibonacci, knapsack, longest common subsequence, edit distance, shortest paths. Define state, transition and base cases.

Key points

  • Top-down vs bottom-up
  • State space size
  • Space optimisation
Example

Fibonacci with memoisation drops from O(2ⁿ) to O(n).

Why it matters

Dynamic programming avoids repeating work when subproblems overlap, which turns exponential problems into practical ones.

Where this is used

  • Computing the cheapest way to split a cutting stock into pieces.
  • Finding the edit distance between two spelling words.
  • Choosing a sequence of jobs that maximises profit subject to time limits.

Frequently asked questions

What is Dynamic programming?

Solves overlapping subproblems once and stores results.

Why is it important to understand dynamic programming?

Dynamic programming avoids repeating work when subproblems overlap, which turns exponential problems into practical ones.

What are the two common ways to implement dynamic programming?

Top-down memoisation stores results of recursive calls, while bottom-up tabulation fills a table from smaller subproblems.

How do I know if DP applies?

Look for optimal substructure, where the best answer uses best answers to subproblems, and overlapping subproblems that repeat.

How is Dynamic programming used in practice?

Typical applications include computing the cheapest way to split a cutting stock into pieces, finding the edit distance between two spelling words and choosing a sequence of jobs that maximises profit subject to time limits.

What should I learn before Dynamic programming?

Study "Minimum spanning trees" first (topic 28 of 104 in Software & Computing). It covers the groundwork this topic builds on.

What are the key points of Dynamic programming?

Top-down vs bottom-up. State space size. Space optimisation.

Can you give an example of Dynamic programming?

Fibonacci with memoisation drops from O(2ⁿ) to O(n).

What comes after Dynamic programming?

The next topic is "Greedy algorithms", which builds directly on this one.

How difficult is Dynamic programming?

It is classed as Beginner in Software & Computing (topic 29 of 104). It is an entry-level topic. It relies only on basic school mathematics and the ideas introduced earlier in this discipline.

Learning path

Want to practise? Open the interactive course for quick checks, quizzes, simulations and progress tracking.

Related topics