liveBook · Manning

Optimal solution

As explained in Grokking AI Algorithms, Second Edition

An optimal solution is a solution that performs best according to the criterion used to evaluate solutions to a problem.

An optimal solution is the solution that performs best according to the criterion used to judge answers to a problem. The criterion depends on the task: a maze may reward the fewest steps, while a knapsack problem may reward the greatest value without exceeding its capacity. A good solution can be useful without being optimal. section 2.3 section 4.2

Treat optimality as a comparison against an explicit evaluation rule:

  • Define the goal, such as minimizing distance or maximizing item value. section 2.3 section 4.2
  • Compare valid solutions using that criterion rather than judging them by appearance or convenience. section 2.3 section 6.9
  • Separate solution quality from computational efficiency: an answer can be better while taking longer to find. section 4.2
  • Check whether the method guarantees the best answer or merely searches for an acceptable one. section 4.2

A maze and a knapsack

In a 10-by-10 maze, valid paths reach the goal while avoiding barriers. Recorded attempts take 17, 23, 17, and 15 actions; the 15-action path is the best among those found. In a knapsack problem, the optimal selection maximizes total value under a weight limit. As the number of items grows, exhaustive comparison becomes expensive, so an evolutionary algorithm may find a desirable solution without guaranteeing the one true optimum. section 2.3 section 4.2

Figure 6.11 The ACO algorithm life cycle
06_11

Trace how ant-colony optimization repeatedly builds tours, updates pheromone trails, records the best solution, and stops after a chosen number of iterations. section 6.4

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines optimality, contrasts it with good-enough answers, and traces selection of the shortest tour without covering formal proofs.
Examples
Uses maze paths, knapsack selections, and ant tours compared by steps, value, or total distance.
What it assumes
Assumes only a problem, candidate solutions, and a way to measure performance; introduces the distinction between good and optimal.
What you can do after
Evaluate solutions by an explicit criterion and recognize when an algorithm finds an acceptable result without guaranteeing optimality.
How it connects
Connects optimal solutions to search algorithms, evolutionary algorithms, the Knapsack Problem, solution fitness, and ant-colony optimization.

Also explained in

Compare how 3 books explain optimal solution →

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.