<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>String on Namtok blog</title>
    <link>https://blog.namtok-it.com/tags/string/</link>
    <description>Recent content in String on Namtok blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <copyright>© 2025 </copyright>
    <lastBuildDate>Tue, 20 Sep 2022 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.namtok-it.com/tags/string/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Rabin-Karp アルゴリズム</title>
      <link>https://blog.namtok-it.com/posts/algorithm_rabin_karp/</link>
      <pubDate>Tue, 20 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://blog.namtok-it.com/posts/algorithm_rabin_karp/</guid>
      <description>&lt;h3 class=&#34;relative group&#34;&gt;&lt;a name=&#34;1&#34;&gt;Rabin-Karp アルゴリズムとは&lt;/a&gt; 
    &lt;div id=&#34;rabin-karp-アルゴリズムとは&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#rabin-karp-%e3%82%a2%e3%83%ab%e3%82%b4%e3%83%aa%e3%82%ba%e3%83%a0%e3%81%a8%e3%81%af&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;2次元パターン照合にも一般化できる&lt;/li&gt;
&lt;li&gt;Rabin さんと Karp さんが考えた&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 class=&#34;relative group&#34;&gt;&lt;a name=&#34;2&#34;&gt;計算量&lt;/a&gt; 
    &lt;div id=&#34;計算量&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e8%a8%88%e7%ae%97%e9%87%8f&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;前処理時間: θ(m)&lt;/li&gt;
&lt;li&gt;最悪実行時間: θ((n-m+1)m)&lt;/li&gt;
&lt;li&gt;平均実行時間:
&lt;ul&gt;
&lt;li&gt;詳細はこちら&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 class=&#34;relative group&#34;&gt;&lt;a name=&#34;3&#34;&gt;考え方&lt;/a&gt; 
    &lt;div id=&#34;考え方&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e8%80%83%e3%81%88%e6%96%b9&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h3&gt;</description>
      
    </item>
    
    <item>
      <title>文字列照合問題で出てくる単語(string match)</title>
      <link>https://blog.namtok-it.com/posts/algorithm_naive_string_match/</link>
      <pubDate>Tue, 20 Sep 2022 00:00:00 +0000</pubDate>
      
      <guid>https://blog.namtok-it.com/posts/algorithm_naive_string_match/</guid>
      <description>&lt;h1 class=&#34;relative group&#34;&gt;&lt;a name=&#34;1&#34;&gt;文字列照合問題&lt;/a&gt; 
    &lt;div id=&#34;文字列照合問題&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e6%96%87%e5%ad%97%e5%88%97%e7%85%a7%e5%90%88%e5%95%8f%e9%a1%8c&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;文字列照合問題 (string-matching problem)&lt;/strong&gt; とは&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;「与えられたパターン P が T に出現する正当なシフトをすべて見つける問題」&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;である。&lt;/p&gt;
&lt;p&gt;ただし、この定義や、文字列照合問題では以下の表現を使うっぽい。&lt;/p&gt;

&lt;h2 class=&#34;relative group&#34;&gt;P, T とは 
    &lt;div id=&#34;p-t-とは&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#p-t-%e3%81%a8%e3%81%af&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;いずれも文字列(string) である&lt;/li&gt;
&lt;li&gt;P の文字数を m, T の文字数を n とし、P[1..l] を P の最初の l 文字の部分文字列とする
&lt;ul&gt;
&lt;li&gt;つまり &lt;strong&gt;P = パターン&lt;/strong&gt;、&lt;strong&gt;T = P を含むかもしれない文字列&lt;/strong&gt; のこと&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 class=&#34;relative group&#34;&gt;パターン P が T のシフト s に出現する (occur with shift s) 
    &lt;div id=&#34;パターン-p-が-t-のシフト-s-に出現する-occur-with-shift-s&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e3%83%91%e3%82%bf%e3%83%bc%e3%83%b3-p-%e3%81%8c-t-%e3%81%ae%e3%82%b7%e3%83%95%e3%83%88-s-%e3%81%ab%e5%87%ba%e7%8f%be%e3%81%99%e3%82%8b-occur-with-shift-s&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;0 &amp;lt;= s ,= n-m かつ T[s+1..s+m] = P[1..m] であることを指す表現。&lt;/li&gt;
&lt;li&gt;つまり、「P と T の左端の文字を合わせて、s 文字だけ P を右に移動したら T の一部と一致する」ということ&lt;/li&gt;
&lt;li&gt;例）P = &amp;ldquo;hello&amp;rdquo;, T = &amp;ldquo;abchello&amp;rdquo; だとするとき、&lt;strong&gt;「パターン P は T のシフト 3 に出現する」&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 class=&#34;relative group&#34;&gt;valid shift, invalid shift 
    &lt;div id=&#34;valid-shift-invalid-shift&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#valid-shift-invalid-shift&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;P と T の左端の文字を合わせて s だけ右に移動(shift)すると、P[1..m] と T[s+1..s+m] は一致する場合に、その shift を &lt;strong&gt;valid shift&lt;/strong&gt; と呼ぶ&lt;/li&gt;
&lt;li&gt;一致しない場合に、その shift を &lt;strong&gt;invalid shift&lt;/strong&gt; と呼ぶ&lt;/li&gt;
&lt;/ul&gt;</description>
      
    </item>
    
  </channel>
</rss>
