
Dynamic Programming
One way to be certain that the solution to a sequence alignment is the best alignment possible is to
try every possible alignment, introducing one or more gaps at every position, and computing an
alignment score based on aligned character pairs and inexact matches. However, the computational
overhead of evaluating all possible alignments of one sequence against another grows exponentially
with the length of the two sequences. For reasonable length sequences of several hundred characters
each, an exhaustive evaluation of potential alignments could take days of computer time without
using specific algorithms developed for sequence alignment, such as dynamic programming.
Dynamic programming is a form of recursion in which intermediate results are saved in a matrix
where they can be referred to later by the program. The comparison can be likened to solving a
series of complex mathematical equations, with the results of one equation feeding the input of
another, with and without the benefit of pen and paper or other temporary storage and retrieval
mechanism. With pen and paper (as with dynamic programming), the intermediate results can be
recorded and the next equation can be solved without regard to the previous or following equation.
Without the pen and paper, it may be impossible for some people to solve the series of equations.
Dynamic programming is processor- and RAM-intensive, but the technique of storing intermediate
values in a matrix can transform an otherwise intractable problem requiring immense computational
capabilities into one that is computationally feasible.
To illustrate the value of dynamic programming in sequence alignment, consider the function:
MaxValue = f (A
i
, B
j
)
In this equation, MaxValue is some function of variables A
i
and B
j
, where i and j are indices to the
variables defined in the tree structure illustrated in Figure 8-7. That is, the possible values of A
i
are
represented by A
1
through A
5
, and the possible values of B are represented by B
1
through B
11
. The
best solution to MaxValue depends on the equation that defines MaxValue. For example, consider the
following possible definition of MaxValue:
MaxValue = (A
i
x B
j
)
Figure 8-7. Dynamic Programming Problem. Values for A and B are defined
in the tree structure. Maximizing MaxValue requires evaluating the
equation for every combination of i and j.