Efficient special cases of Pattern Matching with Swaps - Amir, Amihood; Landau, Gad M.; Lewenstein, Moshe; Lewenstein, Noa (Information processing letters, 1998)
Let a text string T of n symbols and a pattern string P of m symbols from alphabet ∑ be given. A swapped version T′ of T is a length n string derived from T by a series of local swaps (i.e., t′ l ← t l + 1 and t′ l + 1 ← t l ) where each element can participate in no more than one swap. The Pattern Matching with Swaps problem is that of finding all locations i for which there exists a swapped version T′ of T where there is an exact matching of P at location i of T′. It was recently shown that the Pattern Matching with Swaps problem has a solution in time O(nm 1 3 log m log 2 σ) , where σ = min(¦∑¦, m). We consider some interesting special cases of patterns, namely, patterns where there is no length-one run, i.e., there are no a, b, c ϵ ∑ where b ≠ a and b ≠ c and where the substring abc appears in the pattern. We show that for such patterns the Pattern Matching with Swaps problem can be solved in time O( n log 2 m).