A girl and a robot thinking together

Think together · Start with a little story

Each of two secret-code digits can be 0 or 1. The robot writes down all four possibilities: 00, 01, 10, and 11.

Lay out the process

Follow the steps, then explain them in your own words
  1. First digit 000 and 01
  2. First digit 110 and 11
  3. Check each one4 in total

Brute-force search checks every candidate directly, making its reasoning easy to verify.

Estimate the number of candidates first. For a small set, brute force may be a good fit and can also serve as a reference for checking a faster algorithm.

01What is brute-force search?

Brute-force search checks possible answers one by one according to a set of rules.

For example, trying every four-digit combination from 0000 to 9999 means checking up to 10,000 possibilities.

02Is brute-force search foolish?

Not necessarily.

If there are not many candidates, brute force may be the simplest, most reliable, and easiest approach to get right.

03How is brute-force search related to enumeration?

They are closely related.

Enumeration emphasizes “listing candidates systematically,” while brute-force search emphasizes “exploring the candidate space directly.” In many introductory problems, the two phrases describe similar approaches.

04How can you make sure you miss nothing?

The key is to define the search space clearly.

What are the candidates?

All possible answers.

What is the range?

The starting and ending points.

What is the checking rule?

How to tell whether a candidate meets the requirements.

05When does it get slow?

As the number of choice levels grows, the number of candidates may increase quickly.

For example, if each step has 2 choices and you make n choices in a row, there may be:

2n combinations

The number rises sharply even when n grows only a little.

06What else is brute force useful for?

  • Checking whether a more complex algorithm is correct.
  • Handling small-data subtasks.
  • Discovering patterns in a problem.
  • Providing a starting point for optimizations such as pruning and dynamic programming.

What have you learned?

  • Brute-force search systematically checks all candidates.
  • It is not random guessing; it covers the search space completely.
  • Brute force may work very well when the data set is small.
  • The number of candidates may grow exponentially with the problem size.
  • A brute-force algorithm is often an important baseline for optimization.

Next: DFS: Go as Deep as Possible

Your turn to try

If you add a third digit with two choices again, how many possibilities are there?

Ready? Open to see the explanation

There are 8. Each existing possibility can be extended with either 0 or 1, so the total doubles.