01Divide and conquer
Merge sort follows a recipe in three steps:
- Divide: split the array into two halves at
mid = (lo + hi) / 2. - Conquer: sort each half recursively. A piece of one element is already sorted: that is the base case.
- Combine: merge the two sorted halves into one sorted array.
All the real work happens in the combine step. The splitting just keeps cutting until pieces have size 1, then the merges rebuild the array from the bottom up, each time joining two sorted runs into a longer one.