Software Engineer (SDE)dsaintermediate3 interactive MCQs in app
Merge Sort, Quick Sort & Heap Sort
Merge Sort worst-case O(n log n) + stabilityQuick Sort randomized pivot vs O(n^2) sorted traptime/space/stability comparison
Core Concept
Understanding O(n log n) comparison sorts guides engineering trade-offs: **Merge Sort** guarantees worst-case `O(n log n)` and **stability** (preserves relative order of ties!) at the cost of `O(n)` merge space; **Quick Sort** averages `O(n log n)` in-place (`O(log n)` stack) with randomized pivot selection avoiding `O(n^2)` worst case on already-sorted arrays; **Heap Sort** guarantees worst-case `O(n log n)` in `O(1)` extra space (unstable).
Worked Example
sorting `[(score=90,"Amy"), (score=90,"Bob")]` twice (first by name, then by score) preserves `"Amy"` before `"Bob"` ONLY with a stable sort (Merge/Timsort), whereas unstable Quicksort can swap ties!
Common Pitfall
picking deterministic `pivot = arr[0]` on already-sorted input turns Quick Sort into O(n^2)!
Recommended Readings & Practice
Practice Merge Sort, Quick Sort & Heap Sort with 3 graded MCQs & written feedback.
Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.