Pattern Matching with Swaps

Amihood Amir, Yonatan Aumann, Gad M. Landau, Moshe Lewenstein, Noa Lewenstein

Research output: Contribution to journalArticlepeer-review

51 Scopus citations


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′ ← tℓ+1 and t′ℓ+1 ← t), 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 with an exact matching of P in location i of T′. It has been an open problem whether swapped matching can be done in less than O(nm) time. In this paper we show the first algorithm that solves the pattern matching with swaps problem in time o(nm). We present an algorithm whose time complexity is O(nm1/3 log m log σ) for a general alphabet Σ, where σ = min(m, |Σ|).

Original languageEnglish
Pages (from-to)247-266
Number of pages20
JournalJournal of Algorithms
Issue number2
StatePublished - Nov 2000

Bibliographical note

Funding Information:
1A preliminary version of this paper appeared in FOCS 97. 2Partially supported by NSF grant CCR-96-10170, BSF grant 96-00509, and a BIU internal research grant. 3Partially supported by NSF grants CCR-9305873 and CCR-9610238 and by the Israel Science Foundation founded by the Israeli Academy of Sciences and Humanities. 4Partially supported by the Israel Ministry of Science and Arts Grant 8560.


  • Combinatorial algorithms on words
  • Design and analysis of algorithms
  • Nonstandard pattern matching
  • Pattern matching
  • Pattern matching with swaps


Dive into the research topics of 'Pattern Matching with Swaps'. Together they form a unique fingerprint.

Cite this