An improved algorithm to find the length of the longest common subsequence of two strings

Let <i>A</i> and <i>B</i> be strings of common length <i>n.</i> Define <i>LLCS</i>(<i>A, B</i>) to be the length of the longest common subsequence of <i>A</i> and <i>B.</i> Hunt and Szymanski presented an algorithm for finding <i>LLCS</i>(<i>A, B</i>) with time complexity <i>O</i>((<i>r</i> + <i>n</i>)<i>logn</i>), where <i>r</i> is the number of elements in the set {(<i>i, j</i>)|<i>A</i>[<i>i</i>] = <i>B</i>[<i>j</i>]}. In the worst case the algorithm has running time of <i>O</i>(<i>n</i><sup>2</sup><i>logn</i>). We present an improvement to this algorithm which changes the time complexity to <i>O</i>(<i>r</i> + <i>n</i>(<i>LLCS</i>(<i>A, B</i>) + <i>logn</i>)). Some experimental results show dramatic improvements for large <i>n.</i>