LearnViz CompSci
Home / Learn / Algorithms / Brute Force

Beginner Topic 15 of 51 Algorithms

Brute Force

Trying every candidate solution exhaustively.

How it works

Brute force solves a problem by trying every possible candidate and checking each one, so correctness is easy to argue but the running time often grows exponentially or polynomially with a high power. It is the simplest strategy and gives a baseline for judging cleverer algorithms. Pruning obviously invalid candidates turns it into backtracking.

Step-by-step walkthrough

  1. List every possible candidate answer.
  2. Test candidate 1 against the requirements.
  3. Test candidate 2.
  4. Continue until one works or all are tried.
  5. It is simple and always correct, but cost grows quickly, for example 2 to the n subsets.

Where it is used

Small input sizes, password-strength checks, verifying a faster algorithm against a reference in tests, solving tiny puzzles and exploring search spaces where no better approach is known use brute force.

Common pitfall

Time can explode: trying all subsets of 40 items is a trillion cases. Do the arithmetic on the search-space size before coding. Look for structure to prune candidates, sort first, use hashing or switch to dynamic programming. Keep a brute-force version for validating optimized solutions.

Where it fits in the course

Brute Force is topic 15 of 51 in Algorithms, rated Beginner. It follows Radix Sort. The next topic is Two Pointers.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Algorithms quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Brute Force?
Trying every candidate solution exhaustively. It belongs to Algorithms and is a beginner-level topic.
Where do people use Brute Force?
Small input sizes, password-strength checks, verifying a faster algorithm against a reference in tests, solving tiny puzzles and exploring search spaces where no better approach is known use brute force.
What is the most common mistake with Brute Force?
Time can explode: trying all subsets of 40 items is a trillion cases.
What should I learn before this topic?
Start with Radix Sort, the topic just before it in Algorithms.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Algorithms quiz.
Is Brute Force hard to learn?
It is a Beginner topic, so it works as an entry point. If the terms are new, read the explanation twice and try the visualizer before the quiz.
How long does it take to learn Brute Force?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Brute Force?
Radix Sort, Two Pointers, Counting Sort are closely connected. The full list is in the related topics section of this page.
What should I study after Brute Force?
Continue with Two Pointers, the next topic in Algorithms.

Related topics