Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 10 · DSA · Built from the toolbox · with code: Python · about 19 min to read

Play it as a journeyTutor comes with a plan

Build a diff: the table

Recursion and Dynamic Programming
Recursion and Dynamic Programming · Open board

Is the board this build leans on. It says dynamic programming is “just recursion that remembers”: answer each small question once, write it down, and build the big answer from answers already written. This lesson writes those answers into a grid for two whole files, turns the grid into a real diff, and then measures how much writing everything down costs.

Before you start. Dynamic Programming, Worked (filling the table) filled a grid for two protein chains: each cell answered “how much do these two beginnings share, in order?”, and the answer for the whole chains waited in the bottom-right cell. Clinic #22: Longest Common Subsequence solved the same grid as an interview problem, and Git's diff (Myers' algorithm), the case study, later in this track, tells git’s side. Here you build the tool yourself, one file of Python, and watch it run out of room.

Lesson 93 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • June 1975: a three-page paper about running out of memory
  • Two packing lists, and the lines they share
  • The table: one cell for every pair of lines
  • Walking back: the edit script
  • Hunks: what diff -u actually prints
  • The wall: twice the lines, four times the memory
  • The table and the walk back
  • The packing list
  • Against diff -u on 10,000 lines
  • The memory, measured
  • Running out, on purpose
  • What Hirschberg’s paper did, and what it did not
  • In an interview

Terms it explains: Longest Common Subsequence, edit script, context lines, hunk, quadratic, Edit Distance, base case, dynamic programming, greedy, knapsack / edit distance / LCS, memoization, optimal substructure, overlapping subproblems, recurrence, recursion, recursion tree, rolling array, state, tabulation, time, Viterbi.

Review DSA