DEVELOPER TOOL

Diff Checker

Compare two texts side by side with color-coded additions, deletions, and unchanged lines. Powered by the Longest Common Subsequence algorithm.

Diff results will appear here...

The Science of Text Comparison

The Longest Common Subsequence

At the heart of every diff algorithm is the Longest Common Subsequence (LCS) problem. Given two sequences, LCS finds the longest ordered set of elements present in both. For diff, the LCS represents lines that are unchanged — everything outside the LCS is either added or removed. The classic dynamic programming solution runs in O(mn) time where m and n are the line counts. For a 10,000-line file compared to a 10,200-line file, that is roughly 102 million operations — completed in milliseconds on modern hardware.

From Hunt-McIlroy to Myers

The original Unix diff(1974) by Hunt and McIlroy used a hashing approach to find common lines. Eugene Myers improved this in 1986 with an O(ND) algorithm where D is the edit distance — making small diffs extremely fast even on large files. Git uses a variant of Myers' algorithm with refinements for patience diff (better handling of moved code blocks) and histogram diff (optimized for files with many duplicate lines). This tool uses the LCS dynamic programming approach, which is simpler and works well for typical text comparison tasks.

Unified vs. Side-by-Side

The unified diff format (used by git diff) shows changes inline with + and - prefixes and 3 lines of context. It is compact and the standard for patches and code review. Side-by-side view places the original and modified text in parallel columns, making it easier to see exactly what changed at each position. This tool shows a unified view with line numbers for both sides, combining the compactness of unified format with the clarity of dual line numbering.

Real-World Use Cases

Configuration auditing: Compare deployment configs between staging and production to catch environment-specific differences. Content review: Compare article drafts to see editorial changes at a glance. API response debugging: Paste two API responses to find subtle differences in JSON structure. Database migration: Compare schema dumps before and after migrations to verify only intended changes were applied.

Frequently Asked Questions

Is my data sent to any server?

No. The diff computation runs entirely in your browser using JavaScript. Your text never leaves your device, making this tool safe for comparing sensitive configurations, proprietary code, and confidential documents.

What is the maximum text size this tool supports?

The LCS algorithm uses O(mn) memory for the dynamic programming table. For two texts of 5,000 lines each, this requires ~100 MB. Modern browsers handle this well for texts up to about 10,000 lines. For larger files, use command-line tools like diff or git diff.

Does it detect moved lines or only additions and deletions?

This tool reports additions and deletions based on LCS. A moved line appears as a deletion at the original position and an addition at the new position. Detecting moved blocks requires more advanced algorithms like patience diff or histogram diff used in Git.