Divide, Solve, and Combine

Divide and conquer splits a problem into smaller instances, solves them, and combines the answers using a rule tied to the goal.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Find the boundary between subproblems
  2. Account for all the work
  3. State the exact summary a partial result must retain
  4. Prove associativity for regrouping

Find the boundary between subproblems

To find a maximum in 5, 2, 9, 6, divide into pairs. Their maxima are 5 and 9. The overall maximum is 9. A base case can return one element directly if the problem promises a nonempty collection.

Account for all the work

Here the combine step compares two candidates. Merging sorted halves requires visiting both halves. An analysis using recursion trees can expose how much work the combine step adds at each level.[1]

State the exact summary a partial result must retain

To compute a mean over uneven partitions, carry a pair containing sum and count. For readings [3, 7] and [4, 6, 15], the sums are ten and twenty-five. The combined average is seven. Averaging the local means would give a different result. See running averages.

Partition A: (sum=10, count=2)
Partition B: (sum=25, count=3)
Combine:     (sum=35, count=5)
Finalize:    35
5 = 7

Prove associativity for regrouping

Adding sums and counts independently is associative in exact arithmetic, so different partitions can be merged. A partition with no data contributes the pair zero, zero. Test one empty partition and uneven partitions. Floating-point addition order can affect the last digits even when the exact rule is associative.

References

  1. Jeff Erickson, Algorithms ↩