$ 0 0 The problem of sequence alignment is well known and its solution is well described. For an introductory text, see the Wikipedia. The best solution I know involves Dynamic programming, and you can see an example implementation in Java at this site.