Knuth-Morris-Pratt (KMP) algorithm (string matching)