4 ms·
Shockingly, there is a related algorithm that is widely considered much easier to understand and implement. https://cp-algorithms.com/string/z-function.html htt
by vladimirralev 3y ago
Shockingly, there is a related algorithm that is widely considered much easier to understand and implement. https://cp-algorithms.com/string/z-function.html https://cp-algorithms.com/string/z-function.html
And I can certainly implement the Z algorithm in a few mins while I struggle to implement the KMP off the top of my head.
Edit: perhaps a bit better article on this https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/ https://www.geeksforgeeks.org/z-algorithm-linear-time-patter...