16.01.2015 Aufrufe

4. Textalgorithmen Arten von String-Matching-Problemen ...

4. Textalgorithmen Arten von String-Matching-Problemen ...

4. Textalgorithmen Arten von String-Matching-Problemen ...

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

<strong>4.</strong> <strong>Textalgorithmen</strong> <strong>String</strong> <strong>Matching</strong>: Knuth, Morris und Pratt<br />

Satz <strong>4.</strong><strong>4.</strong> Die Algorithmen 1.3 und 1.4 lösen Problem <strong>4.</strong>1 in Zeit O(n +<br />

m) und Platz O(m).<br />

Beweis. sborder kann wie border in Zeit O(m) berechnet werden. Durch<br />

die Verwendung <strong>von</strong> sborder statt border finden in Algorithmus 1.4 nicht<br />

mehr Vergleiche statt als in Algorithmus 1.2. ✷<br />

<strong>4.</strong> <strong>Textalgorithmen</strong> <strong>String</strong> <strong>Matching</strong>: Knuth, Morris und Pratt<br />

Nun erhält man i := 1 + 12 − sborder[12] = 6 und j := sborder[12] = 7.<br />

j<br />

↓<br />

a b a a b a b a a b a a b<br />

a b a a b a b a a b a c a b a a b a b a a b a a b<br />

↑<br />

i<br />

Es tritt wieder ein Mismatch auf, deshalb j := 4 und i := 9.<br />

Information Retrieval — FH Bonn-Rhein-Sieg, SS 06 186<br />

Information Retrieval — FH Bonn-Rhein-Sieg, SS 06 188<br />

<strong>4.</strong> <strong>Textalgorithmen</strong> <strong>String</strong> <strong>Matching</strong>: Knuth, Morris und Pratt<br />

Beispiel <strong>4.</strong>3. [Algorithmus <strong>von</strong> Knuth, Morris und Pratt]<br />

F 7 wird in dem <strong>String</strong><br />

abaababaabacabaababaabaab<br />

Der <strong>String</strong><br />

gesucht. Nach dem Start des Algorithmus ergibt sich ein Mismatch für<br />

j = 12 und i = 1.<br />

j<br />

↓<br />

a b a a b a b a a b a a b<br />

<strong>4.</strong> <strong>Textalgorithmen</strong> <strong>String</strong> <strong>Matching</strong>: Knuth, Morris und Pratt<br />

Die Mismatches setzen sich fort bis j = 1 und i = 13.<br />

j<br />

↓<br />

a b a a b a b a a b a a b<br />

a b a a b a b a a b a c a b a a b a b a a b a a b<br />

↑<br />

i<br />

Ab hier wird nun ein Match ermittelt.<br />

a b a a b a b a a b a c a b a a b a b a a b a a b<br />

↑<br />

i<br />

Information Retrieval — FH Bonn-Rhein-Sieg, SS 06 187<br />

Information Retrieval — FH Bonn-Rhein-Sieg, SS 06 189

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!