Skip to content
Python for Quantitative Finance / Control Flow and Simple Numerical Programs

Exhaustive Enumeration and Approximate Solutions

The first genuinely useful algorithm this vault writes is also its simplest: try every candidate answer in turn until one works, or the search space runs out. This "guess and check by brute force" strategy — exhaustive enumeration — looks naive, but it is often the correct first algorithm to reach for: easy to implement, easy to verify, and, for many problems of modest size, fast enough. This note builds it twice — first as a while loop finding a perfect cube root, then as an equivalent for loop — and then extends it to an approximate root-finding problem, where the goal shifts from "find the exact answer" to "find an answer within a tolerance ϵ\epsilon of the true one". That shift in goal — from exact to approximate, with a named tolerance — is the pattern behind essentially every iterative numerical routine in this vault.
Learning objectives. By the end of this note you should be able to:
  • implement exhaustive enumeration for an exact search (e.g. a perfect cube root) as both a while loop and a for loop with break;
  • state and verify a decrementing function for an exhaustive-enumeration loop;
  • reformulate an "exact root" problem as an "approximate root within tolerance ϵ\epsilon" problem, and explain why this reformulation is often necessary;
  • diagnose why an exhaustive search over a finite grid can fail to find an answer that genuinely exists, and identify the two distinct causes (search range and step size).

In this lesson

  1. Exact search: finding a perfect cube root
  2. From exact to approximate

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.