Making Each Recursive Call Smaller
A recursive decomposition has to make progress toward a base case under a well-founded measure.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Find the measure
A recursive digit counter on a positive decimal integer can replace the input by its floor quotient by ten. At an input of 374 the successive values are 37 and 3. Below ten, return one digit. See integer division for the exact reduction.
Handle skipped and invalid values
A recurrence repeatedly subtracting two can skip zero on odd inputs. A base case covering values at most one could be correct for a properly specified nonnegative domain. Base cases and decreasing steps should be checked together.[1]
Choose a measure that must strictly decrease
In a rectangular grid search, removing an already inspected row decreases the number of rows remaining by one. Dividing the grid into subrectangles needs an argument that each recursive call has fewer cells. Count cells as the measure where the input represents a complete finite rectangle. See recursive interval splitting.
Rectangle dimensions: 3 rows × 4 columns
Remove one row: 3×4 = 12 becomes 2×4 = 8
Last step: 1×4 = 4 becomes 0×4 = 0
Check the subproblem that violates your argument
Cutting just after the last row can produce a smaller empty subproblem and the original rectangle as the other subproblem. An empty-case test alone will pass. Exercise the smallest nonempty rectangle and verify the end reached by each nonempty recursive branch.