Balancing Recursive Subproblem Sizes

The shape of recursive splits affects maximum depth and the amount of work. A split that removes one item can be much deeper than halving the size.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace size only
  2. Account for the combine step
  3. Compare two recurrence shapes at the same input size
  4. Connect depth to the amount of work per level

Trace size only

Starting from sixteen, halving yields 8, 4, 2, and 1 on one path. Removing one yields 15 through 1 and reaches fifteen descents. Recursion depth explains the resulting pressure on active calls.

Account for the combine step

When every split also scans the entire current subproblem, balanced levels of total size sixteen differ from the triangle of sizes in a repeatedly one-sided split. Recursion tree costs give a systematic way to count both.[1]

Compare two recurrence shapes at the same input size

Splitting eight items into four and four, and repeating, reaches singletons after three edges on every path. Splitting one and seven at the first step can give a chain of seven edges when repeated. These trees can have the same number of leaves with very different maximum depths. See recursive call counts.

Balanced largest sizes: 8 → 4 → 2 → 1
Unbalanced largest sizes: 8 → 7 → 6 → 5 → 4 → 3 → 2 → 1
Both have 8 singleton leaves when every split partitions the input

Connect depth to the amount of work per level

If each partition level scans all of its remaining items, unbalanced splits can repeat work on long suffixes. Balanced splitting by count may still be unbalanced by computational cost if items vary drastically in size. Measure both subproblem size and the work of processing it.

References

  1. Jeff Erickson, Algorithms ↩