Skip to the workspace
Pebellslearn by building
Greedy, Backtracking & Dynamic Programming  ›  Lesson

Tabulation & the Best Playlist

Tabulation 40 minFill a table of subproblem answers from the smallest up

dsa / Tabulation & the Best Playlist

Explore each scene at your own pace.

01 · Filling the slot filler without recursion

Filling the slot filler without recursion

Tabulation & the Best Playlist

Definition
Tabulation is a form of dynamic programming that fills a table of subproblem answers from the smallest case upward, so each entry is computed from entries that already exist, without recursion.
In plain words
It is building a times table row by row, starting with the smallest first cells. By the time you reach a harder cell, every number you need to work it out is already written down beside it.

In short: tabulation flips memoization upside down: fill a table from the smallest question up, left to right then down, so each cell's inputs already exist when read. No recursion, no call-stack limit. The table often shrinks to one row — a rolling array — at the cost of losing the choices made.

A 2-row DP table: the "+Aurora" row's highlighted cell has a "skip" arrow straight up and a "take" arrow diagonally up-left, both reading only the row above, with a fill-order arrow sweeping left to right then down

Filling the slot filler without recursion

The Tunebox "commute mix" has a fixed budget. First, last lesson's slot filler with no recursion: fill ways[t] upward, so ways[t - L] already sits in the table when needed:

python
step through it
1lengths = [1, 2]
2ways = [1, 0, 0, 0, 0]
3for t in range(1, 5):
4 for L in lengths:
5 if L <= t:
6 ways[t] += ways[t - L]
7print(ways)
Scene 1 of 7
Project context and further resources
You're building a piece ofTunebox — festival planner
This piece — best_playlist(): The highest-rated playlist that fits a time budget.
Scenario The Tunebox commute mix gets a time budget and a library of rated tracks. The packer picks the highest-rated set of whole tracks that fits the ride.
best_playlist.py
Call the function you wrote — just like your app's frontend would. Edit the inputs and hit Call.
best_playlist(tracks, budget) → dictThe highest-rated playlist that fits the budget: rating, minutes and track names.
try:
returned
Press Run to execute your code.
Press Check to run the tests for this lesson.
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.