Divide and Conquer

Which Algorithms Are Based on Divide and Conquer?

Merge sort, quicksort, binary search and Strassen's matrix multiplication are classic divide-and-conquer algorithms. Here is how to recognize others.

On this page
  1. Merge sort, the standard example
  2. Sorting: merge sort and quicksort
  3. Searching: binary search
  4. Multiplication: Karatsuba and Strassen
  5. Other examples
  6. How to recognize the pattern
  7. Summary

Merge sort is the standard example of a divide-and-conquer algorithm. Many other well-known algorithms follow the same pattern: split the problem into smaller pieces, solve each piece, and combine the results.

Merge sort, the standard example

Merge sort splits a list into two halves, sorts each half the same way, and merges the two sorted halves into one sorted list. The splitting continues until each piece holds a single item, which is already sorted. The halves never overlap, so no sorting work is repeated. The running time is about n log n, which is why merge sort is a common teaching example.

Sorting: merge sort and quicksort

Quicksort is also divide and conquer. It picks a pivot, partitions the items into those smaller than the pivot and those larger, and then sorts each side. Its average running time is about n log n. Its worst case is about n squared, which happens with poor pivot choices. Choosing pivots at random makes the worst case rare in practice.

Quicksort is often described as an in-place algorithm, since it rearranges items inside the array rather than copying them into new space.

Binary search checks the middle item of a sorted list, then keeps only the half that could contain the target. It repeats this on the smaller range. Each step halves the range, so the running time is about log n. Some textbooks call binary search decrease-and-conquer, since it keeps only one half and never combines two answers.

Multiplication: Karatsuba and Strassen

  • Karatsuba multiplication splits large numbers into parts. It uses three multiplications of smaller numbers where a direct split would use four. Its running time is about n to the power of 1.58.
  • Strassen’s matrix multiplication splits matrices into blocks and uses seven recursive multiplications instead of eight. That gives a running time of about n to the power of 2.81, which beats the standard n cubed method for large matrices.

Other examples

  • Fast Fourier transform (FFT) splits a sequence into even- and odd-indexed parts. It runs in about n log n time.
  • Closest pair of points splits the points with a dividing line, solves each side, and then checks the points near that line. It runs in about n log n time.

How to recognize the pattern

Ask two questions:

  1. Can the problem be split into smaller problems of the same kind?
  2. Are those smaller problems independent, so that solving one does not depend on the answer to another?

If both answers are yes, and there is a step that combines the smaller answers, the algorithm likely uses divide and conquer. Most divide-and-conquer methods are written recursively. If that idea is new, learn what is a recursive function first. If the smaller problems overlap instead, dynamic programming may be the better fit.

Summary

Merge sort is the classic divide-and-conquer example. Quicksort, binary search, Karatsuba multiplication, Strassen’s method, the FFT and the closest pair of points follow the same split, solve and combine idea. To recognize one, check whether the problem splits into independent smaller problems of the same kind, and whether their answers can be combined.

The complete guide to divide and conquer

Divide and Conquer Algorithm vs. Dynamic Programming
Read the guide

Keep exploring

Guides from other topics

All topics →