Lecture 5 - Brute Force Algorithm Flashcards

1
Q

What is another name for the brute force algorithm?

A

Exhaustive search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly