Brute Force

Solving a problem by methodically plowing through all the possibilities. For example, solving the EightQueensProblem by generating all possible board positions. Does not scale well.

"When in doubt, use brute force" -- KenThompson (see the entry for "brute force" in the JargonFile for more comment on this.)

Ken probably also knew about BruteForce from his experience programming chess computers. An example of BruteForce is Ken's hardware chess creation, Belle, which became world computer champion not because of any outstanding smarts, but because it could out-search the mainframe competition with special purpose chess-specific circuitry.


On the flip side, OptimiseLast?! Many times the brute force solution has adequate performance for much less complexity in design, development, and maintenance. EncapsulateAlgorithms?, and reimplement using a better algorithm when performance measurements and profiling indicate that the BruteForceSolutions are the problem. This is closely related to DoTheSimplestThingThatCouldPossiblyWork.

It is also important to remember that just because an algorithm is O(n) does not mean it is superior to an O(n^3) solution for small values of n (however it does mean it will scale better, as mentioned above). The additional complexity of many better algorthms can sometimes include large lower order terms. As n gets bigger these terms become irrelevant, but for small n they can sometimes dominate.

-- AndraeMuys


For NpComplete problems, BruteForce is the fastest way to guarantee the correct solution. Not fast, but fastest. Fortunately in many of these problems, the correct solution is not needed, just a good-enough solution. -- RobHarwood


Particularly with the processing power now available, let the processor do the programming. For instance, use immutable (or nearly so) objects for intermediate data, regenerating as required from the master. - DavidWright


See also: BruteForceSolutions


EditText of this page (last edited June 14, 2004) or FindPage with title or text search