Line up two sequences — two words, or two strands of DNA — so the most letters match, allowing gaps where one has something the other lacks. This is how biologists read kinship in genomes: the same algorithm that spell-checks, scaled to the code of life. Slide the gap penalty and watch the alignment rearrange.
Fill a grid scoring every way to align the prefixes: each cell takes the best of a diagonal step (match +1 / mismatch −1), or a gap (the penalty) up or left. The bottom-right is the optimal global score; tracing back reconstructs the alignment, inserting ‘–’ for gaps. A fail-loud self-check throws unless the traced alignment has equal length in both rows AND its recomputed score exactly matches the grid’s optimum — a provably optimal crossing, not a greedy guess (Needleman & Wunsch, 1970).
Linear gap costs here; real bioinformatics uses affine gaps (opening ≫ extending) and substitution matrices (BLOSUM/PAM). Global alignment forces the ends to line up (local Smith-Waterman does not). The DP optimum and traceback validity are exact.