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 11 · DSA · Git Diff · about 24 min to read

Play it as a journeyTutor comes with a plan

Git’s diff (Myers’ algorithm), the case study

Every time you run git diff, something underneath is solving a puzzle: what is the fewest line changes that turn the old file into the new one. It looks like matching text side by side. It is really a shortest-path search, and by the end of this lesson you will see that path every time you read a patch.

Boards

Before you start. Two things from earlier in this track carry the whole idea: a graph is dots joined by one-way streets, and the cheapest route between two dots is a shortest-path question (Graphs (BFS, DFS, Dijkstra, topological sort)). A dynamic-programming table answers a big problem by filling in every smaller version of it first, cell by cell (Recursion & Dynamic Programming). Hashing, turning a chunk of text into one number so two chunks compare instantly (Hashing), is what makes checking a huge file cheap, and it comes back in the second read.

Lesson 96 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

  • 1974: Bell Labs already has an answer, and the classroom fix still chokes
  • The reframe: turn two files into a walk across a grid
  • 1986: Myers, and the rule that makes greedy safe
  • What comes back: the edit script git turns into hunks
  • The stages git actually runs (xdiff/, git’s fork of Davide Libenzi’s libxdiff)
  • The numbers, by hand
  • The boards, one at a time
  • Recommended gitconfig (every knob is something on these boards)
  • The same algorithm, wearing other clothes
  • Sources
  • Cross-links

Terms it explains: indent heuristic, 06 · Linear Space, 3-way merge, DNA sequence alignment, input-sensitive, cost 0, 0-1 BFS, identical futures, middle snake, not-guaranteed-minimal, longest increasing subsequence, similarity, silently not detected, Output-sensitive complexity, Reframe the domain, Recompute instead of remember, git's `xdiff/` directory, edit script, LCS, Levenshtein, subsequence, substring.

Review DSA