https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Two-way_string-matching_algorithm Two-way string-matching algorithm - Revision history 2025-06-25T12:19:52Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.6 https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1283353393&oldid=prev Cedar101: /* Critical factorization */ italics correction 2025-04-01T00:14:12Z <p><span class="autocomment">Critical factorization: </span> italics correction</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:14, 1 April 2025</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 34:</td> <td colspan="2" class="diff-lineno">Line 34:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{mvar|w}} is a prefix of {{mvar|v}} or {{mvar|v}} is a prefix of {{mvar|w}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{mvar|w}} is a prefix of {{mvar|v}} or {{mvar|v}} is a prefix of {{mvar|w}};</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{mvar|w}} occurs on both sides of the cut with a possible overflow on either side. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;. Each factorization trivially has at least one repetition: the string {{mvar|vu}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{mvar|w}} occurs on both sides of the cut with a possible overflow on either side. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;. Each factorization trivially has at least one repetition: the string {{mvar|vu}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{tmath|(u,v)}}. The smallest local period in {{tmath|(u,v)}} is denoted as {{tmath|r(u,v)}}. Because the trivial repetition {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>vu<del style="font-weight: bold; text-decoration: none;">''</del>}} is guaranteed to exist and has the same length as {{mvar|x}}, we see that {{tmath|1 \le r(u,v) \le \mathrm{len}(x)}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{tmath|(u,v)}}. The smallest local period in {{tmath|(u,v)}} is denoted as {{tmath|r(u,v)}}. Because the trivial repetition {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|vu}} is guaranteed to exist and has the same length as {{mvar|x}}, we see that {{tmath|1 \le r(u,v) \le \mathrm{len}(x)}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{tmath|(u,v)}} of {{mvar|x}} such that {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">1=''</del>r(u,v)<del style="font-weight: bold; text-decoration: none;">''</del> = <del style="font-weight: bold; text-decoration: none;">''</del>p(x)<del style="font-weight: bold; text-decoration: none;">''</del>}}. The existence of a critical factorization is provably guaranteed.&lt;ref name=CP91/&gt; For a needle of length {{mvar|m}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{tmath|(u,v)}} of {{mvar|x}} such that {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|r(u,v) <ins style="font-weight: bold; text-decoration: none;">{{</ins>=<ins style="font-weight: bold; text-decoration: none;">}}</ins> p(x)}}. The existence of a critical factorization is provably guaranteed.&lt;ref name=CP91/&gt; For a needle of length {{mvar|m}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> </tr> </table> Cedar101 https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1283353307&oldid=prev Cedar101: /* Critical factorization */ italics correction 2025-04-01T00:13:29Z <p><span class="autocomment">Critical factorization: </span> italics correction</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:13, 1 April 2025</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 28:</td> <td colspan="2" class="diff-lineno">Line 28:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Critical factorization ==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Critical factorization ==</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''factorization''' is a partition {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>(u,v)<del style="font-weight: bold; text-decoration: none;">''</del>}} of a string {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>x<del style="font-weight: bold; text-decoration: none;">''</del>}}. For example, &lt;code&gt;("Wiki","pedia")&lt;/code&gt; is a factorization of &lt;code&gt;"Wikipedia"&lt;/code&gt;.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''factorization''' is a partition {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|(u,v)}} of a string {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|x}}. For example, &lt;code&gt;("Wiki","pedia")&lt;/code&gt; is a factorization of &lt;code&gt;"Wikipedia"&lt;/code&gt;.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''period''' of a string {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>x<del style="font-weight: bold; text-decoration: none;">''</del>}} is an integer {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>p<del style="font-weight: bold; text-decoration: none;">''</del>}} such that all characters {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>p<del style="font-weight: bold; text-decoration: none;">''</del>}}-distance apart are equal. More precisely, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}} holds for any integer {{math|0 &amp;lt; ''i'' &amp;le; <del style="font-weight: bold; text-decoration: none;">''</del>len(x<del style="font-weight: bold; text-decoration: none;">)</del>'' − ''p''}}. This definition is allowed to be vacuously true, so that any word of length {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>n<del style="font-weight: bold; text-decoration: none;">''</del>}} has a period of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>n<del style="font-weight: bold; text-decoration: none;">''</del>}}. To illustrate, the 8-letter word &lt;code&gt;"educated"&lt;/code&gt; has period 6 in addition to the trivial periods of 8 and above. The minimum period of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>x<del style="font-weight: bold; text-decoration: none;">''</del>}} is denoted as {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>p(x)<del style="font-weight: bold; text-decoration: none;">''</del>}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''period''' of a string {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|x}} is an integer {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|p}} such that all characters {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|p}}-distance apart are equal. More precisely, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}} holds for any integer {{math|0 &amp;lt; ''i'' &amp;le; len(<ins style="font-weight: bold; text-decoration: none;">''</ins>x''<ins style="font-weight: bold; text-decoration: none;">)</ins> − ''p''}}. This definition is allowed to be vacuously true, so that any word of length {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|n}} has a period of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|n}}. To illustrate, the 8-letter word &lt;code&gt;"educated"&lt;/code&gt; has period 6 in addition to the trivial periods of 8 and above. The minimum period of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|x}} is denoted as {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|p(x)}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>w<del style="font-weight: bold; text-decoration: none;">''</del>}} in {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>(u,v)<del style="font-weight: bold; text-decoration: none;">''</del>}} is a non-empty string such that:</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|w}} in {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|(u,v)}} is a non-empty string such that:</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>** {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>w<del style="font-weight: bold; text-decoration: none;">''</del>}} is a suffix of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>u<del style="font-weight: bold; text-decoration: none;">''</del>}} or {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>u<del style="font-weight: bold; text-decoration: none;">''</del>}} is a suffix of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>w<del style="font-weight: bold; text-decoration: none;">''</del>}};</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>** {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|w}} is a suffix of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|u}} or {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|u}} is a suffix of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|w}};</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>** {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>w<del style="font-weight: bold; text-decoration: none;">''</del>}} is a prefix of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>v<del style="font-weight: bold; text-decoration: none;">''</del>}} or {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>v<del style="font-weight: bold; text-decoration: none;">''</del>}} is a prefix of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>w<del style="font-weight: bold; text-decoration: none;">''</del>}};</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>** {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|w}} is a prefix of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|v}} or {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|v}} is a prefix of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|w}};</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>w<del style="font-weight: bold; text-decoration: none;">''</del>}} occurs on both sides of the cut with a possible overflow on either side. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;. Each factorization trivially has at least one repetition: the string {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>vu<del style="font-weight: bold; text-decoration: none;">''</del>}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|w}} occurs on both sides of the cut with a possible overflow on either side. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;. Each factorization trivially has at least one repetition: the string {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|vu}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>(u,v)<del style="font-weight: bold; text-decoration: none;">''</del>}}. The smallest local period in {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>(u,v)<del style="font-weight: bold; text-decoration: none;">''</del>}} is denoted as {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>r(u,v)<del style="font-weight: bold; text-decoration: none;">''</del>}}. Because the trivial repetition {{math|''vu''}} is guaranteed to exist and has the same length as {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>x<del style="font-weight: bold; text-decoration: none;">''</del>}}, we see that {{<del style="font-weight: bold; text-decoration: none;">math</del>|1 <del style="font-weight: bold; text-decoration: none;">≤</del> <del style="font-weight: bold; text-decoration: none;">''</del>r(u,v)<del style="font-weight: bold; text-decoration: none;">''</del> <del style="font-weight: bold; text-decoration: none;">≤</del> <del style="font-weight: bold; text-decoration: none;">''</del>len(x)<del style="font-weight: bold; text-decoration: none;">''</del>}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|(u,v)}}. The smallest local period in {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|(u,v)}} is denoted as {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|r(u,v)}}. Because the trivial repetition {{math|''vu''}} is guaranteed to exist and has the same length as {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|x}}, we see that {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|1 <ins style="font-weight: bold; text-decoration: none;">\le</ins> r(u,v) <ins style="font-weight: bold; text-decoration: none;">\le</ins> <ins style="font-weight: bold; text-decoration: none;">\mathrm{</ins>len<ins style="font-weight: bold; text-decoration: none;">}</ins>(x)}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>(u,v)<del style="font-weight: bold; text-decoration: none;">''</del>}} of {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>x<del style="font-weight: bold; text-decoration: none;">''</del>}} such that {{math|1=''r(u,v)'' = ''p(x)''}}. The existence of a critical factorization is provably guaranteed.&lt;ref name=CP91/&gt; For a needle of length {{<del style="font-weight: bold; text-decoration: none;">math</del>|<del style="font-weight: bold; text-decoration: none;">''</del>m<del style="font-weight: bold; text-decoration: none;">''</del>}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{<ins style="font-weight: bold; text-decoration: none;">tmath</ins>|(u,v)}} of {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|x}} such that {{math|1=''r(u,v)'' = ''p(x)''}}. The existence of a critical factorization is provably guaranteed.&lt;ref name=CP91/&gt; For a needle of length {{<ins style="font-weight: bold; text-decoration: none;">mvar</ins>|m}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> </tr> </table> Cedar101 https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1272450884&oldid=prev Mathlate: Fix citation for Critical factorization theorem 2025-01-28T18:10:26Z <p>Fix citation for Critical factorization theorem</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:10, 28 January 2025</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 35:</td> <td colspan="2" class="diff-lineno">Line 35:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;. Each factorization trivially has at least one repetition: the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;. Each factorization trivially has at least one repetition: the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u,v)''}}. The smallest local period in {{math|''(u,v)''}} is denoted as {{math|''r(u,v)''}}. Because the trivial repetition {{math|''vu''}} is guaranteed to exist and has the same length as {{math|''x''}}, we see that {{math|1 ≤ ''r(u,v)'' ≤ ''len(x)''}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u,v)''}}. The smallest local period in {{math|''(u,v)''}} is denoted as {{math|''r(u,v)''}}. Because the trivial repetition {{math|''vu''}} is guaranteed to exist and has the same length as {{math|''x''}}, we see that {{math|1 ≤ ''r(u,v)'' ≤ ''len(x)''}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u,v)''}} of {{math|''x''}} such that {{math|1=''r(u,v)'' = ''p(x)''}}. The existence of a critical factorization is provably guaranteed.&lt;ref name=<del style="font-weight: bold; text-decoration: none;">str-two-way</del>/&gt; For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u,v)''}} of {{math|''x''}} such that {{math|1=''r(u,v)'' = ''p(x)''}}. The existence of a critical factorization is provably guaranteed.&lt;ref name=<ins style="font-weight: bold; text-decoration: none;">CP91</ins>/&gt; For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> </tr> </table> Mathlate https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1272449812&oldid=prev Mathlate: Updated the definitions to include examples, clearer wording, and more consistent style 2025-01-28T18:04:37Z <p>Updated the definitions to include examples, clearer wording, and more consistent style</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:04, 28 January 2025</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 28:</td> <td colspan="2" class="diff-lineno">Line 28:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Critical factorization ==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Critical factorization ==</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* '''<del style="font-weight: bold; text-decoration: none;">Factorization:</del>'''<del style="font-weight: bold; text-decoration: none;"> a string</del> is<del style="font-weight: bold; text-decoration: none;"> considered factorized when it is split into two parts. Suppose</del> a <del style="font-weight: bold; text-decoration: none;">string</del> {{math|''<del style="font-weight: bold; text-decoration: none;">x</del>''}} <del style="font-weight: bold; text-decoration: none;">is</del> <del style="font-weight: bold; text-decoration: none;">split</del> <del style="font-weight: bold; text-decoration: none;">into two parts</del> {{math|''<del style="font-weight: bold; text-decoration: none;">(u, v)</del>''}}, <del style="font-weight: bold; text-decoration: none;">then {{math|''</del>(<del style="font-weight: bold; text-decoration: none;">u</del>,<del style="font-weight: bold; text-decoration: none;"> v</del>)<del style="font-weight: bold; text-decoration: none;">''}}</del> is<del style="font-weight: bold; text-decoration: none;"> called</del> a factorization of <del style="font-weight: bold; text-decoration: none;">{{math|''x''}}</del>.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>*<ins style="font-weight: bold; text-decoration: none;"> A</ins> '''<ins style="font-weight: bold; text-decoration: none;">factorization</ins>''' is a <ins style="font-weight: bold; text-decoration: none;">partition</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">(u,v)</ins>''}} <ins style="font-weight: bold; text-decoration: none;">of</ins> <ins style="font-weight: bold; text-decoration: none;">a</ins> <ins style="font-weight: bold; text-decoration: none;">string</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">x</ins>''}}<ins style="font-weight: bold; text-decoration: none;">. For example</ins>, <ins style="font-weight: bold; text-decoration: none;">&lt;code&gt;</ins>(<ins style="font-weight: bold; text-decoration: none;">"Wiki"</ins>,<ins style="font-weight: bold; text-decoration: none;">"pedia"</ins>)<ins style="font-weight: bold; text-decoration: none;">&lt;/code&gt;</ins> is a factorization of <ins style="font-weight: bold; text-decoration: none;">&lt;code&gt;"Wikipedia"&lt;/code&gt;</ins>.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* '''<del style="font-weight: bold; text-decoration: none;">Period</del>'''<del style="font-weight: bold; text-decoration: none;">:</del> a <del style="font-weight: bold; text-decoration: none;">period</del> {{math|''<del style="font-weight: bold; text-decoration: none;">p</del>''}} <del style="font-weight: bold; text-decoration: none;">for</del> <del style="font-weight: bold; text-decoration: none;">a</del> <del style="font-weight: bold; text-decoration: none;">string</del> {{math|''<del style="font-weight: bold; text-decoration: none;">x</del>''}}<del style="font-weight: bold; text-decoration: none;"> is defined as a value</del> such that <del style="font-weight: bold; text-decoration: none;">for</del> <del style="font-weight: bold; text-decoration: none;">any integer</del> {{math|<del style="font-weight: bold; text-decoration: none;">0 &amp;lt; </del>''<del style="font-weight: bold; text-decoration: none;">i</del>'' <del style="font-weight: bold; text-decoration: none;">&amp;le;</del> <del style="font-weight: bold; text-decoration: none;">''len(x)''</del> <del style="font-weight: bold; text-decoration: none;">−</del> <del style="font-weight: bold; text-decoration: none;">''p''}}</del>, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}<del style="font-weight: bold; text-decoration: none;">.</del> <del style="font-weight: bold; text-decoration: none;">In</del> <del style="font-weight: bold; text-decoration: none;">other</del> <del style="font-weight: bold; text-decoration: none;">words,</del> <del style="font-weight: bold; text-decoration: none;">"</del>{{math|''<del style="font-weight: bold; text-decoration: none;">p</del>''<del style="font-weight: bold; text-decoration: none;">}}</del> <del style="font-weight: bold; text-decoration: none;">is</del> <del style="font-weight: bold; text-decoration: none;">a</del> <del style="font-weight: bold; text-decoration: none;">period</del> <del style="font-weight: bold; text-decoration: none;">of {{math|</del>''<del style="font-weight: bold; text-decoration: none;">x</del>''}} <del style="font-weight: bold; text-decoration: none;">if</del> <del style="font-weight: bold; text-decoration: none;">two</del> <del style="font-weight: bold; text-decoration: none;">letters</del> of {{math|''<del style="font-weight: bold; text-decoration: none;">x</del>''}} <del style="font-weight: bold; text-decoration: none;">at</del> <del style="font-weight: bold; text-decoration: none;">distance</del> {{math|''<del style="font-weight: bold; text-decoration: none;">p</del>''}} <del style="font-weight: bold; text-decoration: none;">always</del> <del style="font-weight: bold; text-decoration: none;">coincide</del>". The minimum period of {{math|''x''}} is<del style="font-weight: bold; text-decoration: none;"> a positive integer</del> denoted as {{math|''p(x)''}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>*<ins style="font-weight: bold; text-decoration: none;"> A</ins> '''<ins style="font-weight: bold; text-decoration: none;">period</ins>'''<ins style="font-weight: bold; text-decoration: none;"> of</ins> a <ins style="font-weight: bold; text-decoration: none;">string</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">x</ins>''}} <ins style="font-weight: bold; text-decoration: none;">is</ins> <ins style="font-weight: bold; text-decoration: none;">an</ins> <ins style="font-weight: bold; text-decoration: none;">integer</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">p</ins>''}} such that <ins style="font-weight: bold; text-decoration: none;">all</ins> <ins style="font-weight: bold; text-decoration: none;">characters</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">p</ins>''<ins style="font-weight: bold; text-decoration: none;">}}-distance</ins> <ins style="font-weight: bold; text-decoration: none;">apart</ins> <ins style="font-weight: bold; text-decoration: none;">are</ins> <ins style="font-weight: bold; text-decoration: none;">equal.</ins> <ins style="font-weight: bold; text-decoration: none;">More precisely</ins>, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}} <ins style="font-weight: bold; text-decoration: none;">holds</ins> <ins style="font-weight: bold; text-decoration: none;">for</ins> <ins style="font-weight: bold; text-decoration: none;">any integer</ins> {{math|<ins style="font-weight: bold; text-decoration: none;">0 &amp;lt; </ins>''<ins style="font-weight: bold; text-decoration: none;">i</ins>'' <ins style="font-weight: bold; text-decoration: none;">&amp;le;</ins> <ins style="font-weight: bold; text-decoration: none;">''len(x)''</ins> <ins style="font-weight: bold; text-decoration: none;">−</ins> ''<ins style="font-weight: bold; text-decoration: none;">p</ins>''}}<ins style="font-weight: bold; text-decoration: none;">.</ins> <ins style="font-weight: bold; text-decoration: none;">This</ins> <ins style="font-weight: bold; text-decoration: none;">definition</ins> <ins style="font-weight: bold; text-decoration: none;">is allowed to be vacuously true, so that any word</ins> of<ins style="font-weight: bold; text-decoration: none;"> length</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">n</ins>''}} <ins style="font-weight: bold; text-decoration: none;">has</ins> <ins style="font-weight: bold; text-decoration: none;">a period of</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">n</ins>''}}<ins style="font-weight: bold; text-decoration: none;">.</ins> <ins style="font-weight: bold; text-decoration: none;">To</ins> <ins style="font-weight: bold; text-decoration: none;">illustrate, the 8-letter word &lt;code&gt;</ins>"<ins style="font-weight: bold; text-decoration: none;">educated"&lt;/code&gt; has period 6 in addition to the trivial periods of 8 and above</ins>. The minimum period of {{math|''x''}} is denoted as {{math|''p(x)''}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)''}} is a non-empty string such that:</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u,v)''}} is a non-empty string such that:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or {{math|''u''}} is a suffix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or {{math|''u''}} is a suffix of {{math|''w''}};</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition<del style="font-weight: bold; text-decoration: none;">,</del> the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side<ins style="font-weight: bold; text-decoration: none;">. Examples include &lt;code&gt;"an"&lt;/code&gt; for &lt;code&gt;("ban","ana")&lt;/code&gt; and &lt;code&gt;"voca"&lt;/code&gt; for &lt;code&gt;("a","vocado")&lt;/code&gt;</ins>. Each factorization trivially has at least one repetition<ins style="font-weight: bold; text-decoration: none;">:</ins> the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)''}}. The smallest local period in {{math|''(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)''}} is denoted as {{math|''r(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)''}}. <del style="font-weight: bold; text-decoration: none;">For</del> <del style="font-weight: bold; text-decoration: none;">any</del> <del style="font-weight: bold; text-decoration: none;">factorization</del> {{math|''<del style="font-weight: bold; text-decoration: none;">(u, v)</del>''}} <del style="font-weight: bold; text-decoration: none;">of</del> {{math|''x''}}, {{math|<del style="font-weight: bold; text-decoration: none;">0</del> <del style="font-weight: bold; text-decoration: none;">&amp;lt;</del> ''r(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)'' ≤ ''len(x)''}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u,v)''}}. The smallest local period in {{math|''(u,v)''}} is denoted as {{math|''r(u,v)''}}. <ins style="font-weight: bold; text-decoration: none;">Because</ins> <ins style="font-weight: bold; text-decoration: none;">the</ins> <ins style="font-weight: bold; text-decoration: none;">trivial repetition</ins> {{math|''<ins style="font-weight: bold; text-decoration: none;">vu</ins>''}} <ins style="font-weight: bold; text-decoration: none;">is guaranteed to exist and has the same length as</ins> {{math|''x''}},<ins style="font-weight: bold; text-decoration: none;"> we see that</ins> {{math|<ins style="font-weight: bold; text-decoration: none;">1</ins> <ins style="font-weight: bold; text-decoration: none;">≤</ins> ''r(u,v)'' ≤ ''len(x)''}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)''}} of {{math|''x''}} such that {{math|1=''r(u,<del style="font-weight: bold; text-decoration: none;"> </del>v)'' = ''p(x)''}}. For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u,v)''}} of {{math|''x''}} such that {{math|1=''r(u,v)'' = ''p(x)''}}.<ins style="font-weight: bold; text-decoration: none;"> The existence of a critical factorization is provably guaranteed.&lt;ref name=str-two-way/&gt;</ins> For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== The algorithm ==</div></td> </tr> </table> Mathlate https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1251871017&oldid=prev Gelingvistoj: /* Critical factorization */ The empty string is not a repetition. 2024-10-18T15:25:27Z <p><span class="autocomment">Critical factorization: </span> The empty string is not a repetition.</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:25, 18 October 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 30:</td> <td colspan="2" class="diff-lineno">Line 30:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Factorization:''' a string is considered factorized when it is split into two parts. Suppose a string {{math|''x''}} is split into two parts {{math|''(u, v)''}}, then {{math|''(u, v)''}} is called a factorization of {{math|''x''}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Factorization:''' a string is considered factorized when it is split into two parts. Suppose a string {{math|''x''}} is split into two parts {{math|''(u, v)''}}, then {{math|''(u, v)''}} is called a factorization of {{math|''x''}}.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;lt; ''i'' &amp;le; ''len(x)'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;lt; ''i'' &amp;le; ''len(x)'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a<ins style="font-weight: bold; text-decoration: none;"> non-empty</ins> string such that:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or {{math|''u''}} is a suffix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or {{math|''u''}} is a suffix of {{math|''w''}};</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> </tr> </table> Gelingvistoj https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1249908230&oldid=prev Fschwarzentruber: /* Critical factorization */ 2024-10-07T13:25:29Z <p><span class="autocomment">Critical factorization</span></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 13:25, 7 October 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 34:</td> <td colspan="2" class="diff-lineno">Line 34:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition, the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition, the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u, v)''}}. The smallest local period in {{math|''(u, v)''}} is denoted as {{math|''r(u, v)''}}. For any factorization, {{math|0 &amp;lt; ''r(u, v)'' ≤ ''len(x)''}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u, v)''}}. The smallest local period in {{math|''(u, v)''}} is denoted as {{math|''r(u, v)''}}. For any factorization<ins style="font-weight: bold; text-decoration: none;"> {{math|''(u, v)''}} of {{math|''x''}}</ins>, {{math|0 &amp;lt; ''r(u, v)'' ≤ ''len(x)''}}.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u, v)''}} of {{math|''x''}} such that {{math|1=''r(u, v)'' = ''p(x)''}}. For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u, v)''}} of {{math|''x''}} such that {{math|1=''r(u, v)'' = ''p(x)''}}. For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> </table> Fschwarzentruber https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1240261068&oldid=prev Belbury: Adding short description: "String-searching algorithm" 2024-08-14T12:30:23Z <p>Adding <a href="/wiki/Wikipedia:Short_description" title="Wikipedia:Short description">short description</a>: &quot;String-searching algorithm&quot;</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 12:30, 14 August 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 1:</td> <td colspan="2" class="diff-lineno">Line 1:</td> </tr> <tr> <td colspan="2" class="diff-empty diff-side-deleted"></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{Short description|String-searching algorithm}}</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Infobox algorithm</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>{{Infobox algorithm</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|name = &lt;!-- Defaults to article name --&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>|name = &lt;!-- Defaults to article name --&gt;</div></td> </tr> </table> Belbury https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1234620235&oldid=prev Asd142513: /* Critical factorization */ 2024-07-15T08:04:56Z <p><span class="autocomment">Critical factorization</span></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 08:04, 15 July 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 28:</td> <td colspan="2" class="diff-lineno">Line 28:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Factorization:''' a string is considered factorized when it is split into two parts. Suppose a string {{math|''x''}} is split into two parts {{math|''(u, v)''}}, then {{math|''(u, v)''}} is called a factorization of {{math|''x''}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Factorization:''' a string is considered factorized when it is split into two parts. Suppose a string {{math|''x''}} is split into two parts {{math|''(u, v)''}}, then {{math|''(u, v)''}} is called a factorization of {{math|''x''}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;<del style="font-weight: bold; text-decoration: none;">le</del>; ''i'' &amp;<del style="font-weight: bold; text-decoration: none;">lt</del>; ''len(x)'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;<ins style="font-weight: bold; text-decoration: none;">lt</ins>; ''i'' &amp;<ins style="font-weight: bold; text-decoration: none;">le</ins>; ''len(x)'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or {{math|''u''}} is a suffix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or {{math|''u''}} is a suffix of {{math|''w''}};</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or {{math|''v''}} is a prefix of {{math|''w''}};</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition, the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition, the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u, v)''}}. The smallest local period in {{math|''(u, v)''}} is denoted as {{math|''r(u, v)''}}. For any factorization, {{math|0 &amp;lt; ''r(u, v)'' ≤ <del style="font-weight: bold; text-decoration: none;">{{!}}</del>''x''<del style="font-weight: bold; text-decoration: none;">{{!}}</del>}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u, v)''}}. The smallest local period in {{math|''(u, v)''}} is denoted as {{math|''r(u, v)''}}. For any factorization, {{math|0 &amp;lt; ''r(u, v)'' ≤ ''<ins style="font-weight: bold; text-decoration: none;">len(</ins>x<ins style="font-weight: bold; text-decoration: none;">)</ins>''}}.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u, v)''}} of {{math|''x''}} such that {{math|1=''r(u, v)'' = ''p(x)''}}. For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''critical factorization''' is a factorization {{math|''(u, v)''}} of {{math|''x''}} such that {{math|1=''r(u, v)'' = ''p(x)''}}. For a needle of length {{math|''m''}} in an ordered alphabet, it can be computed in {{math|2''m''}} comparisons, by computing the lexicographically larger of two ordered maximal suffixes, defined for order ≤ and ≥.&lt;ref name=str-two-way/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> </table> Asd142513 https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1234617898&oldid=prev Asd142513 at 07:47, 15 July 2024 2024-07-15T07:47:56Z <p></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 07:47, 15 July 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 30:</td> <td colspan="2" class="diff-lineno">Line 30:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;le; ''i'' &amp;lt; ''len(x)'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;le; ''i'' &amp;lt; ''len(x)'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or <del style="font-weight: bold; text-decoration: none;">the</del> <del style="font-weight: bold; text-decoration: none;">other</del> <del style="font-weight: bold; text-decoration: none;">way</del> <del style="font-weight: bold; text-decoration: none;">around</del>;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or <ins style="font-weight: bold; text-decoration: none;">{{math|''u''}}</ins> <ins style="font-weight: bold; text-decoration: none;">is</ins> <ins style="font-weight: bold; text-decoration: none;">a</ins> <ins style="font-weight: bold; text-decoration: none;">suffix of {{math|''w''}}</ins>;</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or <del style="font-weight: bold; text-decoration: none;">the</del> <del style="font-weight: bold; text-decoration: none;">other</del> <del style="font-weight: bold; text-decoration: none;">way</del> <del style="font-weight: bold; text-decoration: none;">around</del>;</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a prefix of {{math|''v''}} or <ins style="font-weight: bold; text-decoration: none;">{{math|''v''}}</ins> <ins style="font-weight: bold; text-decoration: none;">is</ins> <ins style="font-weight: bold; text-decoration: none;">a</ins> <ins style="font-weight: bold; text-decoration: none;">prefix of {{math|''w''}}</ins>;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition, the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>*: In other words, {{math|''w''}} occurs on both sides of the cut with a possible overflow on either side. Each factorization trivially has at least one repetition, the string {{math|''vu''}}.&lt;ref name=igm-mlv/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u, v)''}}. The smallest local period in {{math|''(u, v)''}} is denoted as {{math|''r(u, v)''}}. For any factorization, {{math|0 &amp;lt; ''r(u, v)'' ≤ {{!}}''x''{{!}}}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''local period''' is the length of a repetition in {{math|''(u, v)''}}. The smallest local period in {{math|''(u, v)''}} is denoted as {{math|''r(u, v)''}}. For any factorization, {{math|0 &amp;lt; ''r(u, v)'' ≤ {{!}}''x''{{!}}}}.</div></td> </tr> </table> Asd142513 https://en.wikipedia.org/w/index.php?title=Two-way_string-matching_algorithm&diff=1234602482&oldid=prev Asd142513: /* Critical factorization */ 2024-07-15T06:02:46Z <p><span class="autocomment">Critical factorization</span></p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 06:02, 15 July 2024</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 28:</td> <td colspan="2" class="diff-lineno">Line 28:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Before we define critical factorization, we should define:&lt;ref name=CP91/&gt;</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Factorization:''' a string is considered factorized when it is split into two parts. Suppose a string {{math|''x''}} is split into two parts {{math|''(u, v)''}}, then {{math|''(u, v)''}} is called a factorization of {{math|''x''}}.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* '''Factorization:''' a string is considered factorized when it is split into two parts. Suppose a string {{math|''x''}} is split into two parts {{math|''(u, v)''}}, then {{math|''(u, v)''}} is called a factorization of {{math|''x''}}.</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;<del style="font-weight: bold; text-decoration: none;">lt</del>; ''i'' <del style="font-weight: bold; text-decoration: none;">≤</del> <del style="font-weight: bold; text-decoration: none;">{{!}}</del>''x''<del style="font-weight: bold; text-decoration: none;">{{!}}</del> − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>* '''Period''': a period {{math|''p''}} for a string {{math|''x''}} is defined as a value such that for any integer {{math|0 &amp;<ins style="font-weight: bold; text-decoration: none;">le</ins>; ''i'' <ins style="font-weight: bold; text-decoration: none;">&amp;lt;</ins> ''<ins style="font-weight: bold; text-decoration: none;">len(</ins>x<ins style="font-weight: bold; text-decoration: none;">)</ins>'' − ''p''}}, {{math|1=''x''[''i''] = ''x''[''i'' + ''p'']}}. In other words, "{{math|''p''}} is a period of {{math|''x''}} if two letters of {{math|''x''}} at distance {{math|''p''}} always coincide". The minimum period of {{math|''x''}} is a positive integer denoted as {{math|''p(x)''}}.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* A '''repetition''' {{math|''w''}} in {{math|''(u, v)''}} is a string such that:</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or the other way around;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>** {{math|''w''}} is a suffix of {{math|''u''}} or the other way around;</div></td> </tr> </table> Asd142513