On String Pattern Matching: A New Model with a Polynomial Time Algorithm
Ken‐Chih Liu · SIAM Journal on Computing · 1981
A polynomial time algorithm is presented for string pattern matching. Earley’s parsing algorithm is adapted for context-free patterns and is extended to allow the augmentation of the immediate assignment operation of SNOBOL4 and a powerful descriptive operator not previously implemented, set complement. Canonical pattern definition systems are defined to describe patterns for which our algorithm will perform pattern matching. The languages generated by such systems are called extended context-free languages, and are shown to properly contain the family of context-free languages and all families of k-intersection languages which have been shown to establish an infinite hierarchy between the family of context-free languages and the family of context-sensitive languages. It is also shown that for an alphabet of one character, the immediate assignment operator cannot be expressed in terms of the complement operator. Some results on the closure properties and unsolvable problems for this new family are also shown. It is shown that the worst-case time and space complexity of our algorithm is polynomial if the immediate assignment is used, and that the time (space) complexity is cubic (cubic) if the complement but not the immediate assignment operator is used, and is cubic (square) if neither operator is used. Our algorithm has no difficulty with left-recursion or null string alternatives which are problems with the SNONOL4 pattern matching algorithm.