1 / 22

文字列探索

文字列探索. 2011/5/30. 探索する文字列を「パターン」 探索する対象分を「テキスト」と呼ぶ テキスト中で指定されたパターンが出現 する 場所 を見つける操作. 力任せのアルゴリズム. 力任せ法の計算量. テキスト を m 字、パターンをn字とすると     (m-n+1)xn 計算量  O(mn) 実質的計算量 O(n). KMP法. 1970 年、 Cook が理論的に示唆  計算量O ( m+n ) D.E.Knuth と V.R.Pratt,Morris が開発  計算量O(n). KMP法の動き(1). KMP法の動き(2).

jena-benton
Télécharger la présentation

文字列探索

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. 文字列探索 2011/5/30

  2. 探索する文字列を「パターン」 • 探索する対象分を「テキスト」と呼ぶ テキスト中で指定されたパターンが出現する 場所を見つける操作

  3. 力任せのアルゴリズム

  4. 力任せ法の計算量 テキストをm字、パターンをn字とすると     (m-n+1)xn • 計算量  O(mn) • 実質的計算量 O(n)

  5. KMP法 • 1970年、Cookが理論的に示唆  計算量O(m+n) D.E.KnuthとV.R.Pratt,Morrisが開発  計算量O(n)

  6. KMP法の動き(1)

  7. KMP法の動き(2)

  8. KMP法の動き(3)

  9. KMP法における前準備 • ずらし表の作成 パターン “tartar” 「パターンの i文字目で失敗した時に、何文字ずらして再開するか」 • NEXT(0)=1 NEXT(3)=3 • NEXT(1)=1 NEXT(4)=3 • NEXT(2)=2 NEXT(5)=3

  10. KMP法の能力 • O(n) • しかしながら、実際的に力任せ法と大して変わらない。

  11. BM法 • 1977年にR.S.BoyerとJ.S.Moore • 計算量 • 最悪の場合でもO(n), • 平均的な場合(文字の種類が多く,パター ンがあまり長くない)にはO(n/m) • 効率的

  12. BM法

  13. BM法

  14. BM法

  15. BM法

  16. bad-character-shift

  17. Bad-character-shift ANPANMANに対するbad character shift の計算 • N 0 • A 1 • M 2 • P 5 • 他のあらゆる文字 8

  18. good-suffix-shift

  19. good-suffix-shift ANPANMAN n 1 aN 8 mAN 3 nMAN 6 aNMAN 6 pANMAN 6 nPANMAN 6 aNPANMAN 6

  20. bad-character-shiftとgood-suffix-shift           ↓i ANMKODSAZANPANMOPOP    ANPANMAN • good-suffix shift の場合 shift=3 i=+2 ↓ ANMKODSAZANPANMOPOP    ANPANMAN

  21. bad-character-shiftとgood-suffix-shift          ↓i ANMKODSAZANPANMOPOP ANPANMAN • bad-character-shiftの場合 shift=6 i=+8                    ↓      ANMKODSAZANPANMOPOP ANPANMAN

  22. 参考文献 • Wikipedia /english • http://www-igm.univ-mlv.fr/~lecroq/string/node14.html

More Related