Brute Force Algorithm

An algorithm is a step-by-step recipe for solving a problem. A brute force algorithm is one that proceeds in a simple and obvious way, but will require a huge number of steps (perhaps an unfeasably large number of steps) to complete. A brute force algorithm is often the least desirable choice because of the number of steps that will be involved; often, looking for underlying patterns, regularities or organizational tricks will help you discover algorithms that are more clever, more subtle and more efficient.

An example of a Brute Force Algorithm

Suppose that you are given the problem of finding all of the factors of the number 625.

You might say to yourself, "Well, that's easy, just divide every number up to 624 into 625, and for each number that you don't get a remainder, that number is a factor of 625."

If that was how you proposed to solve the problem, you would be taking the approach of a brute force algorithm. First you would divide 625 by 2 and see if it comes out evenly, then divide it by 3, then 4, and so forth. After you had tried every possible divisor, you certainly would know which ones divided 625 evenly. Along the way, however, you might notice that there might be a faster way to do it.

Can you think of a more efficient algorithm than that?

A more efficient algorithm might be more complicated to describe, but when you actually perform all of the steps it will take less time and effort.