資源描述:
《kmp算法[英文詳解](轉(zhuǎn))》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Knuth-Morris-PrattstringmatchingTheproblem:givena(short)patternanda(long)text,bothstrings,determinewhetherthepatternappearssomewhereinthetext.?Lasttime?wesawhowtodothiswithfiniteautomata.Thistimewe'llgothroughthe?Knuth-Morris-Pratt?(KMP)algorithm,whichcanbethoughtofasaneffici
2、entwaytobuildtheseautomata.Ialsohavesome?workingC++sourcecodewhichmighthelpyouunderstandthealgorithmbetter.Firstlet'slookatanaivesolution.supposethetextisinanarray:charT[n]andthepatternisinanotherarray:charP[m].Onesimplemethodisjusttotryeachpossiblepositionthepatterncouldappe
3、arinthetext.Naivestringmatching:for(i=0;T[i]!='