100% found this document useful (1 vote)
550 views14 pages

Brute Force Algorithm Overview and Examples

The document describes the brute force algorithm for string matching. It works by aligning the pattern string at the beginning of the text and comparing each character, moving one position to the right if a mismatch is found until the pattern is found or the text is exhausted. While simple, it runs in O(nm) time where n and m are the text and pattern lengths, which is inefficient for large inputs. The brute force approach is generally applicable but rarely efficient.

Uploaded by

Rakshita Tuli
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
550 views14 pages

Brute Force Algorithm Overview and Examples

The document describes the brute force algorithm for string matching. It works by aligning the pattern string at the beginning of the text and comparing each character, moving one position to the right if a mismatch is found until the pattern is found or the text is exhausted. While simple, it runs in O(nm) time where n and m are the text and pattern lengths, which is inefficient for large inputs. The brute force approach is generally applicable but rarely efficient.

Uploaded by

Rakshita Tuli
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
  • Brute Force
  • Brute Force String Matching
  • Algorithm
  • Example
  • Efficiency
  • Strength of Brute Force
  • Weaknesses of Brute Force
  • Applications
  • Conclusion

BRUTE FORCE ALGORITHM

MADE BY: Rakshita tuli 1469it Salika Chaudhary 1477it

INDEX

Brute Force Brute Force String Matching Algorithm Example Efficiency of Brute force algorithm Strength of Brute force algorithm Weaknesses of Brute force algorithm

Exact Pattern Matching

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.

Various pattern matching algorithms are

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.

Brute-Force String Matching


pattern: a string of m characters to search for text: a (longer) string of n characters to search in

problem: find a substring in the text that matches the pattern

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

all characters are found to match (successful search); or a mismatch is detected

Algorithm

Examples of Brute-Force String Matching

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

Brute-force pattern matching runs in time O(nm).

Challenges

Brute force strengths

Strengths:

It is wide applicable.
It is not complex in nature unlike other algorithms.

It yields reasonable algorithms for some important problems

searching; string matching; matrix multiplication

It yields standard algorithms for simple computational tasks

sum/product of n numbers; finding max/min in a list

Brute force weaknesses

Weaknesses: It rarely yields efficient 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

parsers. spam filters. digital libraries. screen scrapers.

word processors.
web search engines. natural language processing. computational molecular biology. feature detection in digitized images. . . .

BRUTE FORCE ALGORITHM 
MADE BY: 
Rakshita tuli 1469it 
Salika Chaudhary 1477it
INDEX 
Brute Force 
Brute Force String Matching 
Algorithm 
Example 
Efficiency of Brute force algorithm 
Strength of B
Exact Pattern Matching 

String matching algorithms or pattern matching 
algorithms try to find a place where one or several
Brute Force 
 
A straightforward approach, usually based directly on the problem’s 
statement and definitions of the concepts
Brute-Force String Matching 

pattern: a string of m characters to search for 

text: a (longer) string of n characters to
Algorithm
Examples of Brute-Force String Matching
Efficiency 
The expected number of comparisons when 
searching an input text string of n characters 
for a pattern of m char
Efficiency 
Brute-force pattern matching runs in time 
O(nm).
Challenges

You might also like