Invariants and String Properties in the Analysis of the Knuth-Morris-Pratt Algorithm

  • Tibor Ásványi Eötvös Loránd University
Keywords: string-matching, valid shift, prefix function, suffix, invariant

Abstract

This paper is about the string-matching problem. We find the occurrences of a pattern inside a text. First, we formally define the problem and summarise its naive solution. Next, we analyse an efficient method, the Knuth-Morris-Pratt (KMP) algorithm. We prove the correctness of the KMP algorithm. We also analyse its efficiency. Our reasoning is based on the properties of the pattern and the text. It is also based on the invariant properties of KMP. In this way, we could develop an extremely compact and elegant proof. And the method of proving program correctness with the invariant properties of the program is already familiar to our students at our university.

Downloads

Download data is not yet available.
Published
2025-03-16
How to Cite
Ásványi, T. (2025). Invariants and String Properties in the Analysis of the Knuth-Morris-Pratt Algorithm. Acta Cybernetica, 27(1), 5-14. https://doi.org/10.14232/actacyb.308844
Section
Special Issue of ICAI 2023