1 / 14

データ構造とプログラミング技法 (第 10 回)

データ構造とプログラミング技法 (第 10 回). ー文字列照合( KMP 法、 BM 法)ー. 文字列照合. text 中の pat の位置(複数可)を求める。. jは text 中の照合位置 i は pat 中の照合位置 n は text の長さ、 m は pat の長さ. 単純照合法. 単純照合法の無駄. 単純照合法の無駄: 常に大きくスキップできる訳ではない. next[i]. KMP 法. text 中の k 番目の文字で、 pat の i 番目の文字との比較に失敗した時、

omana
Télécharger la présentation

データ構造とプログラミング技法 (第 10 回)

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. データ構造とプログラミング技法(第10回) ー文字列照合(KMP法、BM法)ー

  2. 文字列照合 text中のpatの位置(複数可)を求める。

  3. jはtext中の照合位置 iはpat中の照合位置 nはtextの長さ、 mはpatの長さ 単純照合法

  4. 単純照合法の無駄

  5. 単純照合法の無駄:常に大きくスキップできる訳ではない単純照合法の無駄:常に大きくスキップできる訳ではない

  6. next[i] KMP法 text中のk番目の文字で、patのi番目の文字との比較に失敗した時、 textのk`番目と、patのnext[i]番目の文字との比較から再開する。

  7. next[i]の例 ABABBA 0 1 0 1 3 0 0:共通文字列は存在しない→空であると想定しても,その直後の文字が同じなので矛盾する 1:共通文字列は存在しない→空であると想定すると,その直後の文字と先頭文字が異なるため矛盾しない 3:共通文字列はAB→直後の文字もAとBで不一致

  8. next[i]の例(続き) ABCDABD 0 1 1 1 0 1 3 0:共通文字列は存在しない→空であると想定しても,その直後の文字が同じなので矛盾する 1:共通文字列は存在しない→空であると想定すると,その直後の文字と先頭文字が異なるため矛盾しない 3:共通文字列はAB→直後の文字もAとBで不一致

  9. KMP法:アルゴリズム

  10. BM法:アイデア1 パターンの末尾から照合し,照合に失敗したテキストの 側の文字種が、パターン中の照合に失敗した位置より も左にあるかどうかを探す。

  11. BM法:アイデア1の実現法

  12. BM法:アイデア2 k+m-i

  13. BM法:shift(j)

  14. BM法:アルゴリズム

More Related