What is the Myers Diff Algorithm?
The Myers diff algorithm (also called the Myers difference algorithm) is an efficient algorithm for computing the shortest edit script between two sequences—i.e., the minimal set of insertions and deletions needed to turn one sequence into the other. It runs in O(ND) time, where N is the sum of the lengths of the two sequences and D is the size of the minimal edit script. It is widely used in version control systems like Git, in text editors for diff views, and in tools like JSDiff for comparing JSON, code, or text.
Why It Matters for Diff Tools
A good diff tool should show the smallest, most readable set of changes. The Myers algorithm guarantees that the edit script is minimal, so you see only the necessary additions and deletions. That makes it easier to understand what actually changed when comparing configs, API responses, or code.
How JSDiff Uses It
JSDiff uses the Myers algorithm under the hood for its Lines, Words, and Chars modes, and for generating Patch output. For JSON mode, the tool first normalizes JSON structure and then applies diff logic to produce a semantic comparison. You can read a deeper technical explanation in Myers Diff Algorithm: A Powerful Tool for Efficient Sequence Comparison, or try the algorithm in action on the JSDiff homepage.
Related Terms
- JSON Diff – comparing two JSON documents
- Semantic Diff – meaning-aware comparison
- Glossary index