Overview
Eugene Myers's O(ND) diff algorithm (the default diff engine in Git and GNU diff) frames sequence comparison as finding a minimum-cost path from (0,0) to (N,M) in an edit graph where diagonal moves (matching lines/tokens) have cost 0 and horizontal/vertical moves (deletions/insertions) have cost 1. By tracking the furthest-reaching x-coordinate V[k] on each diagonal k = x - y for edit distance d = 0, 1, ..., D, it runs in O((N + M) D) time, which is near-linear when two file versions have few differences D.