A linear time algorithm for consecutive permutation pattern matching

M. Kubica, T. Kulczyński, J. Radoszewski, W. Rytter, T. Waleń
2013 Information Processing Letters  
We say that two sequences x and w of length m are order-isomorphic (of the We present a simple linear time algorithm for checking if a given sequence y of length n contains a factor which is order-isomorphic to a given pattern x. A factor is a subsequence of consecutive symbols of y, so we call our problem the consecutive permutation pattern matching. The (general) permutation pattern matching problem is related to general subsequences and is known to be NP-complete. We show that the situation
more » ... or consecutive subsequences is significantly different and present an O(n + m) time algorithm under a natural assumption that the symbols of x can be sorted in O(m) time, otherwise the time is O(n + m log m). In our algorithm we use a modification of the classical Knuth-Morris-Pratt string matching algorithm.
doi:10.1016/j.ipl.2013.03.015 fatcat:yp5pzchhzzek5cd2m3zla6qhg4