Home/Glossary/Diff Algorithm

Diff Algorithm

A computational method for comparing two sets of data and identifying differences between them.

DevelopmentAlso called: "file diff", "text comparison"

Diff algorithms power version control, code review, and change detection.

Common algorithms

  • Line-based diff: Compare text line by line (used in Git, diff command).
  • Character-based diff: Compare individual characters (inline changes).
  • Word-based diff: Compare at word boundaries (better for prose).
  • Patience diff: Improved algorithm that handles moved code blocks.

Output formats

  • Unified diff: +/- lines with context (Git standard).
  • Side-by-side: Two columns showing both versions.
  • Inline: Highlighting changes within lines.

Use cases

  • Version control (Git, SVN diff).
  • Code review and pull requests.
  • Configuration file changes.
  • Document comparison and merge.