Even allowing for mismatches, sequence alignment would be easy except for gaps. But it quickly becomes impossible to compare all alignments if we allow them. According to Durbin, the number of possible alignments of 2 sequences of length n with gaps corresponds to the number of ways of picking n objects from a set of 2n objects.
The number of combinations is:
(2n)! / (n!)*(n!)
Using Stirling's approximation
n! ≈ √(2πn) (n/e)n
Durbin says this reduces to:
22n / √(πn)
We can get an idea of how fast these numbers grow using Python:
This brings up the general question of comparing how quickly different functions grow. You've probably heard of big-O notation---O(n).
Here is video of Eric Demaine's MIT open courseware lecture on this topic. And here is a nice post analyzing the video.
Finally, here is the R code for the plot above:
Let's postpone consideration of these points until later:
• how to get the result above using Stirling's approximation
• O(n) analysis
• justification for the O(n) analysis of various algorithms as shown in the figure.