A Space-Efficient Algorithm for Longest Common Almost Increasing Subsequence of Two Sequences
Md Tanzeem Rahat, Md. Manzurul Hasan, Debajyoti Mondal
TL;DR
The paper tackles finding the longest common almost increasing subsequence (LCaIS) of two sequences with a fixed δ, offering a space-efficient Hirschberg-inspired solution that runs in $O(nm\ell)$ time and uses $O(n+m\ell)$ space, where $\ell$ is the LCaIS length. It also presents an output-dependent algorithm that accelerates computation when the number of matching and compatible pairs, $\mathcal{M}$ and $\mathcal{C}$, are small, achieving $O((n+m)\log n + \mathcal{M}\log \mathcal{M} + \mathcal{C}\ell)$ time and $O(\mathcal{M}(\ell+\log \mathcal{M}))$ space. The first approach adapts Hirschberg's divide-and-conquer technique to the LCaIS setting, using DP-like states $P'[j,r]$ and $Q'[j,r]$ to constrain the solution by the largest element, while the second approach models the problem as a specialized DAG over matching pairs and leverages a range-tree to prune the search space. Together, these results improve space consumption relative to prior $O(nm)$-space methods and offer faster performance in favorable input regimes, with clear avenues for further subquadratic improvements and bit-vector optimizations when $\ell$ is small.
Abstract
Let $A$ and $B$ be two number sequences of length $n$ and $m$, respectively, where $m\le n$. Given a positive number $δ$, a common almost increasing sequence $s_1\ldots s_k$ is a common subsequence for both $A$ and $B$ such that for all $2\le i\le k$, $s_i+δ> \max_{1\le j < i} s_j$. The LCaIS problem seeks to find the longest common almost increasing subsequence (LCaIS) of $A$ and $B$. An LCaIS can be computed in $O(nm\ell)$ time and $O(nm)$ space [Ta, Shieh, Lu (TCS 2021)], where $\ell$ is the length of the LCaIS of $A$ and $B$. In this paper we first give an $O(nm\ell)$-time and $O(n+m\ell)$-space algorithm to find LCaIS, which improves the space complexity. We then design an $O((n+m)\log n +\mathcal{M}\log \mathcal{M} + \mathcal{C}\ell)$-time and $O(\mathcal{M}(\ell+\log \mathcal{M}))$-space algorithm, which is faster when the number of matching pairs $\mathcal{M}$ and the number of compatible matching pairs $\mathcal{C}$ are in $o(nm/\log m)$.
