Brute Force Algorithm — Definition & Example
A brute force algorithm is a problem-solving method that lists every possible candidate answer, checks each one, and keeps the best or correct one. It trades speed for certainty: if you check every case, you cannot miss the answer.
An exhaustive search algorithm solves a problem over a finite candidate set . It enumerates every element of , tests each element against the problem's constraints, and evaluates the objective when one applies. It then returns a valid or optimal element. Its correctness follows from the completeness of the enumeration. Its running time is proportional to times the cost of checking one candidate.
Worked Example
Problem: A hiker can carry at most 6 lb of extra gear. A tent weighs 3 lb and is worth 4 points of usefulness, a stove weighs 4 lb and is worth 5 points, and a lantern weighs 2 lb and is worth 3 points. Use brute force to find the most useful load that fits.
Step 1: List every possible candidate. Each item is either packed or left behind, so 3 items give subsets, including packing nothing.
Step 2: Check each subset's weight against the 6 lb limit, and total the points for every subset that fits. Do not skip any.
Step 3: Compare the totals of the loads that fit and keep the largest. You checked every subset, so no better load can exist.
Answer: Pack the stove and the lantern: 6 lb and 8 points. Brute force guarantees this is the best load because all 8 subsets were checked.
Why It Matters
In algorithms and discrete math courses, brute force is the baseline. You write it first because it is easy to prove correct, then use it to test faster methods on small inputs. Its cost grows quickly. With 50 items to pack, there are subsets. A round trip through 20 cities has about possible tours. In cryptography, designers choose key sizes such as 128 bits so that trying all keys is far beyond any computer.
Common Mistakes
Mistake: Stopping as soon as you find a candidate that looks good, such as the first load worth 7 points.
Correction: A brute force search guarantees the optimum only after it checks every case. If you stop early, you have a heuristic, not an exhaustive search. Finish the list before you declare a winner, unless you only need any valid answer and not the best one.
