Knew this one but still fumbled the average vs worst case distinction for Quick Sort.
Start by clearly stating the time complexities for both algorithms in best, average, and worst cases, then briefly explain the reasons behind these complexities, such as pivot selection for Quick Sort and the divide-and-conquer nature of Merge Sort. Finally, mention space complexity and stability to provide a complete comparison.
Pro tip: Emphasize that while Quick Sort has a worst-case O(n^2), its in-place partitioning and good cache performance often make it faster in practice than Merge Sort, which is stable and guarantees O(n log n) but requires O(n) extra space.
Clearly specify best/average O(n log n) and worst O(n^2), and note that the worst case occurs with poor pivot choices (e.g., already sorted input with first/last pivot).
State that Merge Sort is O(n log n) in all cases (best, average, worst) due to its consistent divide-and-conquer splitting and merging.
Briefly explain why: Quick Sort's partitioning can be unbalanced, while Merge Sort always divides the array in half and merges in linear time.
Mention that Quick Sort is in-place (O(log n) stack space) but unstable, whereas Merge Sort requires O(n) auxiliary space and is stable.
Conclude with when each is preferred: Quick Sort for in-memory arrays due to cache efficiency, Merge Sort for linked lists or when stability is needed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.