Overview
Merge Sort splits the array, sorts each half, then merges the sorted halves.
Analogy
Shuffling two sorted decks into one by always picking the smaller top card.
Step-by-step
- Divide array into left and right halves until size 1.
- Recursively sort each half.
- Merge: walk both halves with pointers, take the smaller each step.
- Copy merged result back.
- Return the combined sorted array.
Visual
Recursion tree halves the list; merge step interleaves two sorted rows.
Common mistakes
- Missing the base case (length ≤ 1).
- Forgetting to append remaining tail elements during merge.
- Allocating fresh buffers repeatedly instead of reusing.
Practice questions
- Trace merge sort on [5,2,4,6,1,3] writing each merge output.
- Explain why merge sort is stable and when stability matters.
- Compute recursion tree height and extra memory needed.
Space
O(n) auxiliary for merge buffer