Brute force is an algorithm often used in Computer Science for searching sets of data for an answer. The idea is to take every possible answer, and test it to see if it is correct. Brute force is equivalent to trying every possible combination on a pad lock in order to open it. Although sub-optimal, brute force will find a solution if one exists given enough time.

The last refuge of the incompetent, the first refuge of the competent. While sub-optimal in terms of computation or breaking things, it is generally the fastest-implemented and least error-prone method of searching a space or opening a broken toaster.

BRS = B = brute force and ignorance

brute force adj.

Describes a primitive programming style, one in which the programmer relies on the computer's processing power instead of using his or her own intelligence to simplify the problem, often ignoring problems of scale and applying naive methods suited to small problems directly to large ones. The term can also be used in reference to programming style: brute-force programs are written in a heavyhanded, tedious way, full of repetition and devoid of any elegance or useful abstraction (see also brute force and ignorance).

The canonical example of a brute-force algorithm is associated with the `traveling salesman problem' (TSP), a classical NP-hard problem: Suppose a person is in, say, Boston, and wishes to drive to N other cities. In what order should the cities be visited in order to minimize the distance travelled? The brute-force method is to simply generate all possible routes and compare the distances; while guaranteed to work and simple to implement, this algorithm is clearly very stupid in that it considers even obviously absurd routes (like going from Boston to Houston via San Francisco and New York, in that order). For very small N it works well, but it rapidly becomes absurdly inefficient when N increases (for N = 15, there are already 1,307,674,368,000 possible routes to consider, and for N = 1000 -- well, see bignum). Sometimes, unfortunately, there is no better general solution than brute force. See also NP-.

A more simple-minded example of brute-force programming is finding the smallest number in a large list by first using an existing program to sort the list in ascending order, and then picking the first number off the front.

Whether brute-force programming should actually be considered stupid or not depends on the context; if the problem is not terribly big, the extra CPU time spent on a brute-force solution may cost less than the programmer time it would take to develop a more `intelligent' algorithm. Additionally, a more intelligent algorithm may imply more long-term complexity cost and bug-chasing than are justified by the speed improvement.

Ken Thompson, co-inventor of Unix, is reported to have uttered the epigram "When in doubt, use brute force". He probably intended this as a ha ha only serious, but the original Unix kernel's preference for simple, robust, and portable algorithms over brittle `smart' ones does seem to have been a significant factor in the success of that OS. Like so many other tradeoffs in software design, the choice between brute force and complex, finely-tuned cleverness is often a difficult one that requires both engineering savvy and delicate esthetic judgment.

--Jargon File, autonoded by rescdsk.

On the Usenet newsgroup comp.lang.c, I once saw a newbie ask how to find out whether a number is odd or even (in C, I mean). In C, this is delightfully simple: Just have a squint at the low-order bit; if that's turned "on", it's an odd number:

if ( n & 0x00000001 ) 
    puts( "It's odd . . . DAMNED odd . . ." ); 

Well, some smartass offered the following hilarious solution (those who don't speak C can skip ahead over this typewriter font stuff; there's a plain English explanation afterwards):

int is_odd( int n )
{
    unsigned long i;

    for ( i = 0; i <= 4294967295; i += 2 )
        if ( n == i )
            return 0;

    return 1;
}

Now, what that code does is it compares a number (n) to every even number that the computer can reasonably deal with: 4294967295 is the largest integer you can express in thirty-two bits. So in some cases, that code would make more than two billion comparisons before coming up with an answer. I thought converting 0xffffffff into decimal was a nice touch.

That's brute force, baby.

John's first word was "factory." Richard's was "book." When John was five, he began work in his father's store. When Richard was five, he began reading War and Peace. When John was ten, he sold stock in a fledgling company specializing in intergalactic travel, and made several million dollars. When Richard was ten, he awed a group of scholars with the depth of his insight into Plato's dialectic. John never went to college, and still made his way to the top of a company specializing in the biotechnologies. Richard got a scholarship to Harvard, where he majored in theology and literature and graduated with highest honors, going on to head the school's literature department.

The brothers met once a year at their parents' house for Thanksgiving dinner. Every year the great industrialist watched, silent, while his brother chatted with their parents about Sartre and Marx. Sometimes the brothers argued about God or politics, arguments that Richard always won by sheer eloquence and range of historical knowledge. John's arguments were brief and uninspiring, and it would have taken more discerning ears than his parents' to detect their logical force. John always drove a little bit above the speed limit after these dinners.

John had worked throughout his life to make contacts in every field and every industry. When a neuroscientist working in a small backwater town hit something big, John 's impeccably placed contacts found out. One decided to call him. Within days, the scientist had sold out to John for a small fortune, promised never to mention his discovery to anyone, and flown off for a permanent vacation somewhere sunny. A careful observer would have noticed a slight bump in the research and development budget of John's company around this time. If this observer was granted admittance to company headquarters, he might have wondered why access to a whole wing of the building was barred by a line of guards and fingerprint scanners. But if anyone at the company noticed these changes, they did not tell the world.

Months later, John's company released a new product. Richard was watching television over a copy of the Wall Street Journal, and happened to see the first commercial for it. Years of intellectual supremacy had stamped an unconscious half-smile on Richard's face, a smile that shriveled like a salted slug as John's steady voice narrated:

"How long does it take to read a three hundred page novel? If you're like many people, it takes about twenty hours out of your life. We want to give you those twenty hours back. The Athens implant is a safe, powerful way of learning. Instead of spending decades reading the classics, you will be able to integrate the entire Western canon into your subconscious mind in minutes. From Homer to Hobbes, from Locke to Sinclair Lewis, you will have a deep understanding of every writer that shaped the way we see the world. Call today!"

Richard never got an Athens implant. As fewer and fewer people needed an education in the humanities, Richard's department was riddled by layoffs. Those students that still bothered to attend his classes looked bored, and answered his questions almost before he asked them. Richard could not sleep, and his walk became a jittery shuffle. When he heard a group of construction workers debating the finer points of French existentialism, some barrier lifted in his mind. He climbed to the roof of a skyscraper in the center of town. He walked to the edge, spread his arms, and felt the cold wind running through his hair.

Log in or register to write something here or to contact authors.