One of the most fundamental method for comparing two given strings $A$ and $B$ is the longest common subsequence (LCS), where the task is to find (the length) of an LCS of $A$ and $B$. In this paper, we deal with the STR-IC-LCS problem which is one of the constrained LCS problems proposed by Chen and Chao [J. Comb. Optim, 2011]. A string $Z$ is said to be an STR-IC-LCS of three given strings $A$, $B$, and $P$, if $Z$ is a longest string satisfying that (1) $Z$ includes $P$ as a substring and (2) $Z$ is a common subsequence of $A$ and $B$. We present three efficient algorithms for this problem: First, we begin with a space-efficient solution which computes the length of an STR-IC-LCS in $O(n^2)$ time and $O((\ell+1)(n-\ell+1))$ space, where $\ell$ is the length of an LCS of $A$ and $B$ of length $n$. When $\ell = O(1)$ or $n-\ell = O(1)$, then this algorithm uses only linear $O(n)$ space. Second, we present a faster algorithm that works in $O(nr/\log{r}+n(n-\ell+1))$ time, where $r$ is the length of $P$, while retaining the $O((\ell+1)(n-\ell+1))$ space efficiency. Third, we give an alternative algorithm that runs in $O(nr/\log{r}+n(n-\ell'+1))$ time with $O((\ell'+1)(n-\ell'+1))$ space, where $\ell'$ denotes the STR-IC-LCS length for input strings $A$, $B$, and $P$.
翻译:比较两个给定字符串$A$和$B$的最基本方法之一是求解最长公共子序列(LCS),其任务是找出$A$和$B$的LCS(的长度)。本文研究Chen和Chao [J. Comb. Optim, 2011]提出的约束LCS问题之一——STR-IC-LCS问题。若字符串$Z$是满足以下条件的最长字符串,则称$Z$为三个给定字符串$A$、$B$和$P$的STR-IC-LCS:(1) $Z$包含$P$作为子串;(2) $Z$是$A$和$B$的公共子序列。我们针对该问题提出了三种高效算法:首先,我们给出一种空间高效解法,能够在$O(n^2)$时间和$O((\ell+1)(n-\ell+1))$空间内计算STR-IC-LCS的长度,其中$\ell$是长度为$n$的字符串$A$和$B$的LCS长度。当$\ell = O(1)$或$n-\ell = O(1)$时,该算法仅需线性$O(n)$空间。其次,我们提出一种更快的算法,运行时间为$O(nr/\log{r}+n(n-\ell+1))$(其中$r$为$P$的长度),同时保持$O((\ell+1)(n-\ell+1))$的空间效率。第三,我们给出另一种替代算法,其运行时间为$O(nr/\log{r}+n(n-\ell'+1))$,空间复杂度为$O((\ell'+1)(n-\ell'+1))$,其中$\ell'$表示输入字符串$A$、$B$和$P$的STR-IC-LCS长度。