A Systematic Approach to Algorithms

Vijay K. Garg · The University of Texas at Austin

Chapter 9. Divide and Conquer

Recurrence-driven algorithms: split, recurse on halves, combine. Parallel composition is what makes them fly.

This page: Classical forms. View LLP forms »

This page collects the classical / parallel-composition implementations of the divide-and-conquer algorithms developed in this chapter. The lattice-linear (LLP) reformulations and chapter setup live on the LLP companion page.

MergeSort (parallel)

MergeSort with the two recursive calls composed via [ ... [] ... ] — they are independent, so an LL backend can dispatch them in parallel. The Merge aux runs sequentially after both halves are sorted. The sequential variant lives in Chapter 4 (Sorting).

Time complexity: $O(n \log n)$, where $n$ is the size of the array.

QuickSort (parallel)

Lomuto-partition QuickSort. The two recursive calls on the left and right partitions are composed via [ ... [] ... ]; the partition step runs sequentially. The sequential variant lives in Chapter 4 (Sorting).

Time complexity: $O(n^2)$ worst case, $O(n \log n)$ on average, where $n$ is the size of the array.

ClosestPair

Plane-sweep closest-pair via divide and conquer. Points are pre-sorted by $x$-coordinate; the shared "best squared distance" register $G[0]$ flows through the recursion as an explicit parameter so the parallel branches see the same value.

Time complexity: $O(n \log n)$, where $n$ is the number of points.

CountingInversions

Counts inversions $(i, j)$ with $i < j$ and $A[i] > A[j]$ via the MergeSort framework. The merge step counts cross-half inversions for free; total time $O(n \log n)$.

Time complexity: $O(n \log n)$, where $n$ is the size of the array.

Karatsuba

Karatsuba's $O(n^{\log_2 3})$ integer multiplication. Three half-size multiplications ($x_0 y_0$, $x_1 y_1$, $(x_0 + x_1)(y_0 + y_1)$) instead of four; combine by subtracting two of the products from the third.

Time complexity: $\Theta(n^{\log_2 3}) \approx \Theta(n^{1.585})$ for $n$-digit inputs.

Looking ahead

Divide-and-conquer recurrences underpin Chapter 10 (dynamic programming, where overlapping subproblems force memoisation), Chapter 11 (network flow, where augmenting-path methods recurse on residual graphs), and the parallel-prefix / tree-contraction primitives that appear throughout the book's parallel chapters.