Skip to content
BENIBIX Learn

Brute Force

Development🧮 Algorithms & Data StructuresAlgorithm Design Techniques

Also known as Brute-Force Search, Exhaustive Search

You try each possible answer in turn. You stop when one works.

Think of it like

Think of it like a big ring of keys. You try each key until one opens the door.

Example

Jack forgot his 3-digit bike lock code. Trying every code from 000 to 999 opens it in at most 1,000 tries.

Why it matters

It gives a right answer to test smart methods against. It is fine when the options are few.

Definition

Brute force solves a problem by trying every possible answer until one works. It is simple to write and always finds the answer, if there is one. The trouble is the number of tries, which can grow huge very fast. A 4-digit code has 10,000 options, but a 12-letter password has far more than anyone could try. It is often the first version, before a smarter one replaces it.

Common mistake

Shipping brute force without counting the options. Ten items have 3.6 million orders; twenty have far too many to try.

Key takeaways

  1. 1
    Try everything. Until one works.
  2. 2
    Always correct. If it finishes.
  3. 3
    Grows fast. Count the options first.

Compare