Strings 2008 2 3: Difference between revisions
From MDWiki
Jump to navigationJump to search
ThomasHuber (talk | contribs) No edit summary |
ThomasHuber (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
[[Image:Brute force schema.png|naive string search algorithm]] | [[Image:Brute force schema.png|naive string search algorithm]] | ||
--[[User:ThomasHuber|ThomasHuber]] 13: | |||
If the text is n characters long and the pattern is m characters long, it takes O(n*m) steps. | |||
--[[User:ThomasHuber|ThomasHuber]] 13:07, 10 January 2008 (EST) |
Revision as of 02:07, 10 January 2008
Brute force (naive) search
The simplest, but also least efficient approach to text searching is to check whether the pattern matches the string at every possible position in the string. This is called the brute-force or naive string search algorithm. The procedure is illustrated below.
If the text is n characters long and the pattern is m characters long, it takes O(n*m) steps.
--ThomasHuber 13:07, 10 January 2008 (EST)