Time: O(n log n) | Space: O(n) for merge sort, O(log n) for quicksort avg
Note O(n log n) is the theoretical lower bound for comparison-based sorting. If an interviewer asks you to do better, the input must have special structure (e.g., bounded integers for counting sort). Heap operations on n elements also yield O(n log n).
Note Time: O(n log n) always. Space: O(n). Stable. Guaranteed O(n log n) regardless of input - unlike quicksort. Preferred for linked lists (no random access needed, O(1) space merge). The merge function is reusable in many problems.
Frequently asked questions
How do you merge sort?
Interview Prep covers this with 2 copy-ready snippets on this page. The "O(n log n) - Linearithmic Time" snippet in Interview Prep uses `Typical of efficient comparison-based sorts. You divide (log n levels) and do O(n) work...`.
Which code does the Interview Prep example use?
The "O(n log n) - Linearithmic Time" snippet uses `Typical of efficient comparison-based sorts. You divide (log n levels) and do O(n) work...`, from the Big-O Notation section of the Interview Prep cheat sheet.
What other Interview Prep snippets are shown for "merge sort"?
Besides "O(n log n) - Linearithmic Time", this page also shows "Merge Sort".
Is there anything to watch out for?
Yes. For "O(n log n) - Linearithmic Time": O(n log n) is the theoretical lower bound for comparison-based sorting. If an interviewer asks you to do better, the input must have special structure (e.g., bounded integers for counting sort). Heap operations on n elements also yield O(n log n).