Chapter 3: Q46E (page 231)
In this exercise we deal with the problem of string matching.
- Explain how to use a brute-force algorithm to find the first occurrence of a given of m characters, called the target, in a string of n characters, where, called the text. [Hint: Think in terms of finding a match for the first character of the target and checking successive characters for a match, and if they do not all match, moving the start location one character to the right].
- Express your algorithm in pseudocode.
- Give a big-O estimate for the worst-case time complexity of the brute-force algorithm you described.
Short Answer
- If match is found, algorithm should stop and return to the location of the occurrence of string.
- else i := i + 1
return location.
3. O(n log n)