Reading preferences
Concept

Divide and Conquer

Split a problem into smaller pieces, solve them, and combine their answers.

divide and conquer, recursion, split, combine

Share a pile of cards

Two friends can count separate halves of a pile, then add their counts. Each friend can split their own half again until a pile is small enough to count.

Divide and conquer follows that pattern: divide a problem into smaller pieces, solve each piece, then combine the answers. Often it uses recursion to repeat the same idea.

Why use it and where it helps

Some large problems are easier to understand as smaller versions. Merge sort uses the idea to sort smaller halves and merge them. A search can also discard part of its input; binary search follows only one half rather than solving both halves. Dividing does not guarantee a speedup: the extra splitting and combining can cost time or memory.

Follow a split

To add [2, 4, 1, 3], split into [2, 4] and [1, 3], then split again.

             [2, 4, 1, 3]
              /         \
          [2, 4]       [1, 3]
          /   \         /   \
        [2]  [4]      [1]  [3]
          \   /         \   /
            6             4
              \         /
                   10

Each single item is already a sum. Combining 2 + 4 gives 6; combining 1 + 3 gives 4; finally 6 + 4 gives 10. The slashes show the two halves, not parallel execution.

See the reasoning

Follow the example one step at a time

Split a row into smaller sums, then combine the answers. This is a prepared teaching demonstration, not live code execution.

Start with one problem

[2, 4, 1, 3]

We want the sum of the whole row.

Python illustration

def range_sum(numbers, start, end):
    if start == end:
        return 0
    if end - start == 1:
        return numbers[start]
    middle = (start + end) // 2
    left = range_sum(numbers, start, middle)
    right = range_sum(numbers, middle, end)
    return left + right


numbers = [2, 4, 1, 3]
print(range_sum(numbers, 0, len(numbers)))
print(range_sum([], 0, 0))

Prepared output — not live execution:

10
0

The range includes start but excludes end; the caller supplies valid indices. The empty range has sum zero. We pass indices instead of copying halves. This example illustrates the idea, not a faster way to sum a list.

Time, space, and common mistakes

Each item appears in one leaf, and there are O(n) calls for n items, so the time is O(n). Balanced splits create O(log n) levels and use O(log n) call-stack space for non-empty input. A loop can sum the list in O(n) time with O(1) extra space. Other divide-and-conquer algorithms have different costs.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. What are the main steps of divide and conquer?
2. Why does the example return immediately for a one-item range?
3. How are the two smaller sums combined?
4. Does splitting always make a problem faster?

References and further reading