Home

GXTXAYB

GXTXAYB is a seven-character string frequently used as an input example in discussions of the Longest Common Subsequence (LCS) problem. It is typically paired with the string AGGTAB in educational materials to illustrate a dynamic programming solution to LCS.

The two strings have lengths seven and six, respectively. In this canonical example, the longest common subsequence

The example serves to demonstrate the construction of a two-dimensional dynamic programming table, where the entry

In broader terms, GXTXAYB is used to teach the standard LCS algorithm, which runs in O(mn) time

of
GXTXAYB
and
AGGTAB
is
GTAB,
of
length
four.
This
subsequence
preserves
the
relative
order
of
characters
in
both
strings
but
does
not
require
contiguity.
at
position
(i,
j)
stores
the
length
of
the
LCS
of
the
prefixes
GXTXAYB[1..i]
and
AGGTAB[1..j].
The
recurrence
compares
the
current
characters
and
propagates
the
maximum
length
from
neighboring
cells,
illustrating
core
DP
ideas
such
as
overlapping
subproblems
and
optimal
substructure.
and
O(mn)
space
for
strings
of
lengths
m
and
n.
Variations
may
employ
space
optimization
or
alternative
formulations,
but
the
GXTXAYB–AGGTAB
example
remains
a
common
reference
point
for
explaining
the
concept.