Pairwise sequence alignment finds the best way to line up two biological sequences (here, DNA strands) by inserting gaps so that matching bases line up while penalizing mismatches and gaps. This is the algorithmic core behind tools like BLAST used to compare genes across organisms.
The 3D grid is the dynamic-programming matrix: each cell (i, j) holds the best score for aligning the first i letters of sequence A against the first j letters of sequence B. Column height and color encode the score value. The glowing path traces the optimal traceback through the matrix.
Needleman-Wunsch (global) recurrence:
F(i,j) = max(
F(i-1,j-1) + s(a_i,b_j), // diagonal: match/mismatch
F(i-1,j) + gap, // up: gap in B
F(i,j-1) + gap) // left: gap in A
Smith-Waterman (local) adds a floor:
F(i,j) = max(0, ...same three terms...)
optimal score = max over all F(i,j)
- Global / Local toggle switches between Needleman-Wunsch (whole-sequence alignment) and Smith-Waterman (best matching subsequence).
- Match / Mismatch / Gap sliders set the scoring scheme s(a,b) and gap penalty used to fill the matrix.
- Traceback speed controls how fast the marker replays the optimal path from the matrix corner back to the start.
- New Sequences generates two fresh random DNA strands (A, C, G, T) and recomputes the full matrix.
Real aligners (BLAST, Smith-Waterman implementations in genomics pipelines) use exactly this recurrence at massive scale to find homologous genes, detect mutations, and build phylogenetic trees.