liveBook · Manning

Brute-force search

As explained in Grokking AI Algorithms, Second Edition

A brute-force approach systematically evaluates every possible combination or candidate in a problem's search space.

Brute-force search systematically tries every available candidate or combination without using special knowledge about the problem. It is also called uninformed, unguided, or blind search. The approach is straightforward: represent the possibilities, explore them, and keep track of visited states when cycles could cause endless repetition. section 2.8

Brute-force search is useful when:

  • The search space is small enough that checking every possibility is practical. section 2.8
  • You need a dependable baseline that can find an answer without domain-specific guidance. section 2.8
  • You can compare all valid candidates and select the best one, as in a constrained optimization problem. section 4.2

Two common search orders are depth-first search, which follows one path as far as possible, and breadth-first search, which examines all options at one depth before going deeper. Both may require visited-state tracking. Generating the entire possibility tree first is usually wasteful, so search algorithms generate and inspect it iteratively. section 2.8

Knapsack: inspect every combination

Suppose a knapsack has a fixed weight limit and several items with different weights and values. A brute-force solution calculates every combination, discards combinations exceeding the weight limit, compares the values of the remaining combinations, and chooses the most valuable one. This can produce the optimal answer for a small example, but the number of combinations makes the approach increasingly expensive as the dataset grows. section 4.2

Figure 2.15 All possible movement options represented as a tree

Use the maze tree to inspect how brute-force search represents alternative paths, valid solutions, and a path invalidated by the no-repeated-block constraint. section 2.8

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains traversal order, visited-state tracking, iterative tree generation, and exhaustive knapsack evaluation, but avoids implementation code.
Examples
Uses maze paths, network routing, web crawling, social connections, and knapsack item combinations as concrete examples.
What it assumes
Assumes a problem representation as a tree or graph and teaches traversal choices and visited-state constraints through examples.
What you can do after
Evaluate small search spaces exhaustively while preventing cycles and comparing valid candidates for an optimal result.
How it connects
Connects brute-force search to uninformed search, depth-first search, breadth-first search, graphs, trees, and evolutionary algorithms.

Also explained in

Compare how 7 books explain brute-force search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.