Lecture 5 - Brute Force Algorithm Flashcards
1
Q
What is another name for the brute force algorithm?
A
Exhaustive search
2
Q
Steps of the naive brute force algorithm?
A
- set the current starting position in the text to be zero
- compare text and string characters left to right until the entire string is matched or a character mismatches
- in case of mismatch - return to starting position + 1
- in case of a match break and return
3
Q
What is the complexity of the brute force approach?
A
O(nm)
There are m char comparisons at each (n-(m+1)) char, which is m * n.
4
Q
What complexity of the brute force approach do we expect on average? WHY?
A
O(n), as typically there will only be one comparison per character to show mismatch.(string not iterated through)