Brute Force Algorithm
Brute Force Algorithm
INDEX
Brute Force Brute Force String Matching Algorithm Example Efficiency of Brute force algorithm Strength of Brute force algorithm Weaknesses of Brute force algorithm
String matching algorithms or pattern matching algorithms try to find a place where one or several strings (also called patterns) are found within a larger string or text.
Brute force algorithm Boyer Moore Algorithm Aho - Corasik Algorithm etc.
Brute Force
A straightforward approach, usually based directly on the problems statement and definitions of the concepts involved
Examples: 1. String and pattern matching
2.
Computing n! Multiplying two matrices Searching for a key of a given value in a list
3.
4.
pattern: a string of m characters to search for text: a (longer) string of n characters to search in
Brute-force algorithm Step 1 Align pattern at beginning of text Step 2 Moving from left to right, compare each character of pattern to the corresponding character in text until
Step 3 While pattern is not found and the text is not yet exhausted, realign pattern one position to the right and repeat Step 2
Algorithm
Efficiency
The expected number of comparisons when searching an input text string of n characters for a pattern of m characters is:
Where NC is expected number of comparisons and c is the size of alphabet of the text.
Efficiency
Challenges
Strengths:
It is wide applicable.
It is not complex in nature unlike other algorithms.
Some brute force algorithms are unacceptably slow e.g., the recursive algorithm for computing Fibonacci numbers It is not as constructive/creative as some other design techniques
Applications
word processors.
web search engines. natural language processing. computational molecular biology. feature detection in digitized images. . . .