1 / 26

Knuth-Morris-Pratt algoritmus (KMP)

Knuth-Morris-Pratt algoritmus (KMP). Farkas Attila FAANABI.ELTE. Knuth-Morris-Pratt algoritmus (KMP). Knuth-Morris-Pratt algoritmus (KMP). Next []. Knuth-Morris-Pratt algoritmus (KMP). Knuth-Morris-Pratt algoritmus (KMP). Knuth-Morris-Pratt algoritmus (KMP).

padma
Download Presentation

Knuth-Morris-Pratt algoritmus (KMP)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Knuth-Morris-Pratt algoritmus (KMP) Farkas Attila FAANABI.ELTE

  2. Knuth-Morris-Pratt algoritmus (KMP)

  3. Knuth-Morris-Pratt algoritmus (KMP) Next[]

  4. Knuth-Morris-Pratt algoritmus (KMP)

  5. Knuth-Morris-Pratt algoritmus (KMP)

  6. Knuth-Morris-Pratt algoritmus (KMP)

  7. Knuth-Morris-Pratt algoritmus (KMP)

  8. Knuth-Morris-Pratt algoritmus (KMP)

  9. Knuth-Morris-Pratt algoritmus (KMP)

  10. Knuth-Morris-Pratt algoritmus (KMP)

  11. Knuth-Morris-Pratt algoritmus (KMP)

  12. Knuth-Morris-Pratt algoritmus (KMP)

  13. Knuth-Morris-Pratt algoritmus (KMP)

  14. Knuth-Morris-Pratt algoritmus (KMP)

  15. Knuth-Morris-Pratt algoritmus (KMP)

  16. Knuth-Morris-Pratt algoritmus (KMP)

  17. Knuth-Morris-Pratt algoritmus (KMP)

  18. Knuth-Morris-Pratt algoritmus (KMP)

  19. Knuth-Morris-Pratt algoritmus (KMP)

  20. Knuth-Morris-Pratt algoritmus (KMP)

  21. Knuth-Morris-Pratt algoritmus (KMP)

  22. Knuth-Morris-Pratt algoritmus (KMP)

  23. C++ Implementáció

  24. C++ Implementáció

  25. C++ implementáció teszt környezettel • #include <iostream> • #include <string> • usingnamespacestd; • string S="blablablablalakban"; • string M="blablalak"; • int next[100]; • int n=S.length(); • int m=M.length(); • bool u=false; • int k=0; • voidinitnext(){ • int i,j; • i=1; • j=0; • next[0]=0; • while(i<m-1){ • if(M[i]==M[j]){ • i++; • j++; • next[i]=j; • }else{ • if(j==0){ • i++; • next[i]=0; • }else{ • j=next[j]; • } • } • } • // tombindexelesjavitasa -1 iranyba • int tmp[100]; • for(int i=0;i<99;i++){ • tmp[i]=next[i+1]; • } • for(int i=0;i<99;i++){ • next[i]=tmp[i]; • } • } • void KMP(){ • initnext(); • int i,j; • i=0; • j=0; • while(i<n && j<m){ • if(S[i]==M[j]){ • i++; • j++; • }else{ • if(j==0){ // a minta elejer ugrunk • i++; • }else{ • j=next[j]; • } • } • } • if(j==m){ • k=i-m; • u=true; • }else{ • u=false; • } • } • int main(){ • cout << S << endl; • cout << M << endl; • initnext(); • cout << "------------" << endl; • for(int i=0;i<m-1;i++){ • cout << next[i] ; • } • cout << endl; • KMP(); • cout << "Megtalalhato?(0=nem;1=igaz)" << u << endl; • return 0; • }

  26. Vége

More Related