Comparison Mode

Side-by-side: use case, requirements, complexity, strengths, weaknesses, example problems, and a clear “choose this when…”.

Quick SortSorting
Heap SortSorting
Use caseGeneral in-memory sorting with the best average speed.Sorting with a guaranteed bound and O(1) extra space; partial sorting (top k).
RequirementsRandom access and a good pivot strategy.An array that can be heapified in place.
Time complexityAverage O(n log n), worst O(n^2).Best, average, worst O(n log n).
Space complexityO(log n) expected stack.O(1) auxiliary, iterative.
StrengthsFastest in practice; cache friendly; partition step reusable for quickselect.Worst-case guarantee; in place; stop early after k extractions for top-k.
WeaknessesQuadratic worst case; not stable; recursive.Poor cache locality makes it 2-3x slower than quick sort; not stable.
Example problemsSort colors, kth largest element, sort an array.Kth largest element, top k frequent elements, sort an array under strict memory limits.
Choose this whenChoose quick sort (randomized) for raw speed when an occasional bad case is acceptable.Choose heap sort when you need a hard O(n log n) guarantee with constant extra memory, or only the k largest elements.