Content deleted Content added
Timy2shoes (talk | contribs) m Incorrect chance of a random match. Didn’t take into account that there are 26 possible matches. Tags: Visual edit Mobile edit Mobile web edit |
Likes2wiki (talk | contribs) m →Background: fix capitalization |
||
Line 47:
A string-matching algorithm wants to find the starting index <code>m</code> in string <code>S[]</code> that matches the search word <code>W[]</code>.
The most straightforward algorithm, known as the "[[Brute-force search|
Usually, the trial check will quickly reject the trial match. If the strings are uniformly distributed random letters, then the chance that characters match is 1 in 26. In most cases, the trial check will reject the match at the initial letter. The chance that the first two letters will match is 1 in 26 (1 in 26^2 chances of a match over 26 possible letters). So if the characters are random, then the expected complexity of searching string <code>S[]</code> of length ''n'' is on the order of ''n'' comparisons or ''O''(''n''). The expected performance is very good. If <code>S[]</code> is 1 million characters and <code>W[]</code> is 1000 characters, then the string search should complete after about 1.04 million character comparisons.
|