Brute Force and Exhaustive Search
Brute Force is a straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved.
- String matching: the checking and locating of specific sequences of data of some pattern among raw data or a sequence of tokens.
- Design a brute-force string matching algorithm.
pattern: a string of m characters to
search for
text: a (long) string of n characters to search in
matching: a fully match for all the characters
comparison: compare 2 characters (positive or negative result)
A brute force solution to a problem involving search for an element with a special property, usually among combinatorial objects such as permutations, combinations, or subsets of a set.
- generate a list of all potential solutions to the problem in a systematic manner
- evaluate potential solutions one by one, disqualifying infeasible ones and, for an optimization problem, keeping track of the best one found so far
- when search ends, announce the solution(s) found
- Traveling Salesman Problem: Given n cities with known distances between each pair, find the shortest tour that passes through all the cities exactly once before returning to the starting city.
-
Knapsack problem: Given a set of items, each with a weight and a value, determine which items to include in the collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.