Open the editor

Computer science · University

Dynamic Programming Slides

Free animated slides, ready to teach: 6 slides where every step appears on a click and the diagrams move. Play them right here, present them full screen, or copy them into your account to edit.

A real Tracé deck playing in your browser. No account needed.

What the lesson covers

Dynamic programming solves a problem by solving each smaller subproblem once and storing the answer. Students see a recursive Fibonacci tree repeat work, fill a table bottom-up instead and use the same idea to find the fewest coins for an amount.

The slides, one by one

1 Dynamic programming

Never solve the same problem twice

Why does a simple recursive Fibonacci take ages for n = 50?

2 Plain recursion repeats the same work

f(n) = f(n - 1) + f(n - 2)
f(5)\textsf{ makes 15 calls; }f(50)\textsf{ billions}

3 Store each answer once, in a table

Bottom-up: from the smallest case

n + 1\textsf{ steps instead of billions}

4 Fewest coins

Coins are worth 1, 3 and 4. Find the fewest coins that make 6. Let c(a) be the fewest coins for amount a.

→ c(a) = 1 + the smallest of c(a − 1), c(a − 3), c(a − 4)

c(0) = 0,\ c(1) = 1,\ c(2) = 2
c(3) = 1,\ c(4) = 1
c(5) = 1 + \min(1, 2, 1) = 2
c(6) = 1 + \min(2, 1, 2) = 2

2 coins (3 + 3); greedy 4 + 1 + 1 would use 3

5 Quick check

A bottom-up table for Fibonacci up to f(30) needs about how many additions?

  • 30²
  • 29
  • 2³⁰
  • 1
Show the answer

29

Each of f(2) … f(30) is one addition of two stored values: 29 additions.

6 What to remember

Overlapping subproblems: solve once

Memoise: store answers as you go

Or fill a table bottom-up

Exponential becomes polynomial

Challenge: How would you count the number of ways to climb 10 stairs taking 1 or 2 steps at a time?

Every slide is built click by click: text, formulas and pictures come in one step at a time, so the class follows the reasoning instead of reading ahead. Graphs with sliders can be dragged live while you present.

Make your own version with AIChange the level, the numbers or the language: type the topic and get a new deck that moves in about 30 seconds. Free, no account needed.

Questions teachers ask

What is dynamic programming?

A method for problems built from overlapping subproblems: store each sub-answer in a table (memoisation or bottom-up) so it is computed once. Fibonacci drops from exponential time to n steps this way.

Are these slides really free?

Yes. Watch them on this page or present them full screen with no account. Making your own copy to edit is free too.

Can I change the slides before my lesson?

Yes. Press "Make my own copy" and the deck becomes one of your projects in the Tracé editor, where you can change the text, the numbers, the colours or the order of the clicks.

Do they work on a classroom projector or an interactive whiteboard?

Yes. They run in the browser on any laptop, so anything that shows your screen works. Press the right arrow or click to go to the next step.