VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 12: Dynamic programming

Lesson 12.1 of 16 in this module Unrolled Pro

Dynamic Programming from First Principles

Dynamic programming is recursion whose subproblems repeat, solved once each and stored. On a running example, the cheapest way to hop to the end of an array with jumps of up to k: from plain recursion that re-solves the same positions exponentially often, to memoisation (top-down, O(n · k)), to a table filled in order (bottom-up), to keeping only the last k values, and finally a monotonic deque that makes it O(n). Then the four questions that define any DP (state, recurrence, base case, order), and how to recognise a DP problem.

about 10 min 3 Python examples 1 quick checks

The question this module answers: what if the recursion tree is huge, but the number of distinct subproblems is small? Lesson 8.1 showed naive Fibonacci recomputing the same calls exponentially often, and memoisation collapsing it to O(n). Dynamic programming (DP) is that idea made systematic: define subproblems, express each one through smaller ones, and solve every subproblem exactly once, in an order where its dependencies are already solved.

ML context.

  • Sequence alignment and similarity: edit distance and longest common subsequence (lessons 12.11–12.12, 12.15) for fuzzy matching, evaluation metrics like word error rate, and dynamic time warping.
  • Decoding: the Viterbi algorithm finds the most likely tag sequence in HMMs and CRFs (lesson 12.16); CTC loss sums over alignments with a DP.
  • Reinforcement learning: value iteration and the Bellman equation are DP over states.
  • Planning under budgets: knapsack-style choices of features, models or batches (lesson 12.6).

1. The running problem: cheapest hops to the end

Task: you stand at index 0 of an array cost. From index i you may jump forward by 1, 2, …, k positions. Landing on index j costs cost[j]. Return the minimum total cost to reach the last index.

best(i) = cheapest cost to reach the end from i = min over j in i + 1 … i + k of cost[j] + best(j). The recursion tree branches k ways at every level, and the same positions are solved again and again.

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Dynamic Programming from First Principles"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee