# Length of the longest common subsequence between overlapping words

###### Abstract

Given two random finite sequences from such that a prefix of the first sequence is a suffix of the second, we examine the length of their longest common subsequence. If is the length of the overlap, we prove that the expected length of an LCS is approximately , where is the length of an LCS between two independent random sequences. We also obtain tail bounds on this quantity.

## 1 Introduction

A word is a finite sequence of symbols over some alphabet. We write for the length of a word . We write for the th symbol of , indexing starting with . A subsequence of a word is a word obtained by deleting symbols from . A common subsequence between two words and is a subsequence of both and . A natural notion of similarity between two words is the length of the longest common subsequence (LCS) for the two. We write for the length of an LCS between words and . A subword of a word is a subsequence consisting of contiguous symbols from . We denote the subword of consisting of symbols through by . For a set , we write for the subsequence given by .

To take a concrete example, let and . Then , as evidenced by the common subsequence abda. In this paper we are interested in the LCS between words chosen randomly.

As the nature of the symbols will not be important to us, will use for the alphabet. We’ll write to indicate that is a word chosen uniformly at random from .

Let where . Then we define

See [3] for a proof that this limit exists, as well as upper and lower bounds on . Refer to [8] for the best known bounds on and a deterministic method to determine accurate bounds for for . In [6] it is shown that as .

In this paper, we examine a related problem: the LCS between two random words which overlap. Namely, let , pick , and choose and . Thus a suffix of is the same as a prefix of . We say that is shifted from by . We will examine where .

This is motivated in part by an application to DNA sequencing. In this process, we have two sections of DNA which can be regarded as words over the alphabet of nucleotides. The pieces of DNA may overlap, and we wish to determine whether the similarity between them is more than coincidence, i.e., if they are indeed from the same section of the genome.

Acknowledgment: We thank Miklós Rácz for telling us of the problem.

## 2 Results

For shifted from by , the length of the
overlap () is a lower bound on the length of the LCS since the
overlapping section is *a* common subsequence between the two. When
is much less than ,
we might think that the overlap does not matter and
behaves like . This is indeed so, as the following
two theorems show.

###### Theorem 1.

There exists a constant such that for any ,

when is sufficiently large.

###### Theorem 2.

There exists a constant such that for any ,

when is sufficiently large.

All logarithms in this paper are to base .

We expect that with high probability. This is supported by [7] which shows that the standard deviation of is .

## 3 Tools

Here we collect several auxiliary results.

###### Lemma 1 ([1], Theorem 1.1).

Let where each is a probability space and has the product measure. Let . Let be a random variable given by .

We call Lipschitz if whenever differ in at most one coordinate.

###### Lemma 2 (Azuma’s inequality, [2], Theorem 7.4.2).

If is Lipschitz, then

###### Lemma 3 (Hoeffding’s inequality, [5]).

Suppose are independent random variables with . Then for all ,

###### Lemma 4.

Let be independent random variables, each of which is exponential with mean . Let . Then

###### Proof.

We may assume that , for otherwise the result is trivial. With hindsight set . Then

From this it follows that . Therefore by Markov’s inequality we have

where in the penultimate line we used the inequality , which can be established by considering the Taylor expansion of . ∎

In this paper, we will weaken this bound to

(1) |

using .

## 4 Proof of Theorem 1

There is a geometric way to interpret a common subsequence. Consider a line segment from to , and a second from to . Now we place the symbols from on the first line segment and those from on the second. For each pair of symbols in and , connect them with an edge if the symbols are equal. The LCS, then, is the largest set of noncrossing edges. Furthermore, symbols aligned vertically will be certainly equal by the nature of the shift. See Figs. 1