You are on page 1of 14

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. . . .

You might also like