The algorithm Let s be the given string. We want to find a substring t of s with the maximum self-alignment value . Let s[1, j] be the substring of s that consists of the first j letters. Informally, we use w(i, j) to denote the maximum self-alignment value of a suffix tj of s[1, j] such that there are i letters at the right end of the self-alignment of tj that are aligned with spaces and scored as . Note that, the right end of the self-alignment of tj could contain more than i spaces. However, only the last i spaces are scores as each and the rest of them are scored as the score for μ(x, Δ). Let Tj be the set of all suffixes of s[1, j]. For a substring t of s and an integer i, Π(t, i) = {π(t)|π(t) ∈ Π(t) and |tk-1tk| ≥ i}, where tk-1, tk are the last two repeats in π(t). We define to be the maximum V(·, c, i) value of all the partitions in Π(t, i), where t is a substring in Tj. To compute w(i, j) using dynamic programming method, we first consider the boundary values of w(i, j). We set w(0, j) = -∞ since we do not allow suf(tk-1tk, i) to be empty. Note that, by definition, i ≤ j. Lemma 1 For a sequence s of length n, w(j, j) = c·j for 1 ≤ j ≤ n. Proof. For a partition π(t) = {t1, t2, ..., tk} satisfying t ∈ Tj and π(t) ∈ Π(t, j), from the definition of Π(t, j), |tk-1tk| ≥ j. Since t is a suffix of s[1, j] and |t| ≥ |tk-1tk| ≥ j, we have t = s[1, j] and 1 ≤ k ≤ 2. Consider the self alignment of π(t) such that the last j letters in t are mapped to spaces with score . Two cases arise. Case 1: k = 1 and t = t1 = s[1, j]. In this case, the middle alignment is empty. Thus, V(π(t), c, j) = × (|t1| + j) = c·j. Case 2: k = 2 and t = t1t2 = s[1, j]. In this case, the middle alignment is the alignment between |t2| spaces and t2. By the assumption that >μ(Δ, x), V(π(t), c, j) = |t2| × μ(Δ, x) + × (|t1| + j)