1 min lesson
Computing the diff
Name the parts in "Computing the diff" and give the practical job of each one.
Step 1 of 2
Computing the diffline-level for review, char-level for precision
A diff is the minimal set of changes that turns the old text into the new. The textbook engine is a longest-common-subsequence (LCS) computation: find the longest run of unchanged lines and everything outside it is an insertion or deletion. Most production diffs run LCS at line granularity for a readable review, then refine to character granularity inside changed lines.
Diff granularity tradeoffs
- Line-level
- Readable review UI, cheap; coarse on one-character changes
- Character-level
- Precise highlighting; noisier and more expensive
- Hybrid (line then char)
- What editors ship: line diff, char-refine changed regions
Know that LCS underlies the minimal diff; you rarely code full Myers in a screen.