Practice Discrete Math

Algorithms / Merge Sort Divide Conquer

Least You Need to Know: Merge Sort, Divide-and-Conquer, and Recurrence Reasoning

Merge sort is the classic divide-and-conquer sorting example: split the array, sort each half recursively, then merge the two sorted halves. Its main reasoning patterns are recurrence setup, combine-step cost, and the distinction between guaranteed `O(n log n)` time and the extra linear auxiliary memory used by the common array implementation.

The least you need to know

Key notation

T(n) = 2T(n/2) + Theta(n) standard recurrence for balanced merge sort
stable equal keys preserve relative order
merge combine two sorted lists into one sorted list

Tiny worked example

  • Split an array of length `n` into left and right halves.
  • Recursively sort each half.
  • Merge the two sorted halves by repeatedly taking the smaller front element.
  • Because the merge touches each element once, the combine step is linear.

Common mistakes

How to recognize this kind of problem

Start practice