Skipping elements without reordering them

A subsequence is obtained by deleting zero or more elements without reordering those retained. The longest-common-subsequence problem maximizes the length of a result that is a subsequence of both inputs.

For abc and ac, the result ac skips b in the first input. Optimal results need not be unique. Returning one does not invalidate equally long alternatives or establish which edits an author actually performed.

References: [1]

Using pairs of remaining suffixes

A dynamic-programming state stores the optimum for two remaining suffixes. Equal leading elements can be retained before advancing both; unequal ones compare the best results after skipping one element on either side.

An empty suffix gives length zero. After filling dependencies, following compatible choices recovers one result. The optimum length and the actual elements selected are separate outputs.

References: [2] [1]

Length calculation versus reconstruction

For nonempty inputs of lengths m and n, the standard table uses O(mn) constant-work states and space. Keeping adjacent rows reduces auxiliary space for length alone, but does not directly retain every reconstruction choice.

The alignment does not interpret meaning or automatically penalize long gaps differently. Character, token and other element choices define different comparisons. Contiguous matches, substitution costs and multiple-input variants require their own formulations.

References: [1] [2]