Developer Tools
Diff Algorithm (Myers & LCS)
A program that compares two files and highlights exactly what text was added, changed, or removed.
Detailed Explanation
A diff algorithm compares two sequences of data (typically text files or source code lines) and determines the sequence of additions, deletions, and modifications required to transform one into the other. The Myers diff algorithm (Eugene W. Myers, 1986) operates on an edit graph to compute the Shortest Edit Script (SES) in O(ND) time and space. It powers Git diffs, Unix diff utilities, and modern code comparison tools. You can test this using the Text Diff Checker.
Key Technical Takeaways
- Computes the minimum number of insertions and deletions (Shortest Edit Script).
- The foundation of Git version control, pull request reviews, and patch creation.
- Operates at multiple granularities: line-by-line, word-by-word, and intra-line character levels.
- Normalizes line endings (LF vs CRLF) and whitespace to prevent false positive changes.
Interactive Companion Tool
Try the Diff & Code Compare
Run calculations and transformations instantly in your browser with zero latency.