Why it matters

NW is foundational alignment. Understanding shapes bio DP.

Advertisement

The architecture

Fill DP table: match / mismatch / gap in x / gap in y.

Backtrack for alignment.

Needleman-Wunsch DPMatch / mismatchdiagonalGap x / yhorizontal / verticalBacktrackreconstruct alignmentNeedleman + Wunsch 1970; foundation for many aligners; affine gap variants common
Needleman-Wunsch.
Advertisement

How it works end to end

Score matrix (BLOSUM / PAM).

Affine gap penalty (Gotoh).

Space O(mn) or Hirschberg O(m+n).