Strings 2008 2 3: Difference between revisions

From MDWiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 8: Line 8:
If the text is n characters long and the pattern is m characters long, it takes O(n*m) steps.
If the text is n characters long and the pattern is m characters long, it takes O(n*m) steps.


[[Strings_2008_2_4 | goto Visual comparison of strings]]


--[[User:ThomasHuber|ThomasHuber]] 13:07, 10 January 2008 (EST)
--[[User:ThomasHuber|ThomasHuber]] 13:07, 10 January 2008 (EST)

Revision as of 02:12, 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.

naive string search algorithm


If the text is n characters long and the pattern is m characters long, it takes O(n*m) steps.

goto Visual comparison of strings

--ThomasHuber 13:07, 10 January 2008 (EST)