We investigate the classical Morris-Pratt and Knuth-Morris-Pratt pattern matching algorithms from the perspective of computer architecture, focusing on the effects of incorporating a simple branch prediction mechanism into the computational model. Assuming a fixed pattern and a random text, we derive precise estimates for the number of branch mispredictions incurred by these algorithms when using local predictors. Our analysis relies on tools from automata theory and Markov chains, offering a theoretical framework that can be extended to other text processing algorithms and more sophisticated branch prediction strategies.
@InProceedings{nicaud_et_al:LIPIcs.CPM.2025.8, author = {Nicaud, Cyril and Pivoteau, Carine and Vialette, St\'{e}phane}, title = {{Branch Prediction Analysis of Morris-Pratt and Knuth-Morris-Pratt Algorithms}}, booktitle = {36th Annual Symposium on Combinatorial Pattern Matching (CPM 2025)}, pages = {8:1--8:17}, series = {Leibniz International Proceedings in Informatics (LIPIcs)}, ISBN = {978-3-95977-369-0}, ISSN = {1868-8969}, year = {2025}, volume = {331}, editor = {Bonizzoni, Paola and M\"{a}kinen, Veli}, publisher = {Schloss Dagstuhl -- Leibniz-Zentrum f{\"u}r Informatik}, address = {Dagstuhl, Germany}, URL = {https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.CPM.2025.8}, URN = {urn:nbn:de:0030-drops-231027}, doi = {10.4230/LIPIcs.CPM.2025.8}, annote = {Keywords: Pattern matching, branch prediction, transducers, average case complexity, Markov chains} }
Feedback for Dagstuhl Publishing