Sorting Algorithms: Time Complexity Cheatsheet
Classic sorting algorithms — average/worst time, space, and stability for interview recall.
10 cards· by GuruOwl
Make a deck like this from your own PDF — free.
Try it- 01What is the average and worst-case time of mergesort?Both Θ(n log n). Extra space Θ(n). Stable.mergesort
- 02What is the average time of quicksort? Worst case?Average Θ(n log n); worst Θ(n²) (bad pivots). Typical in-place variants use Θ(log n) stack space. Not stable (typical).quicksort
- 03What is heapsort’s time complexity?Θ(n log n) time, Θ(1) auxiliary space (array heap). Not stable.heapsort
- 04What is insertion sort’s best and worst case?Best Θ(n) (already sorted); worst Θ(n²). Stable; excellent for small/nearly sorted arrays.insertion
- 05What is selection sort’s time complexity?Θ(n²) always. Not stable (typical). Minimal swaps.selection
- 06What is bubble sort’s time complexity?Worst/average Θ(n²); best Θ(n) with early exit if no swaps. Stable.bubble
- 07What does it mean for a sort to be stable?Equal keys keep their original relative order.stability
- 08Lower bound for comparison-based sorting in the worst case?Ω(n log n) — decision-tree bound.theory
- 09When can counting/radix sort beat n log n?When keys have limited range/structure (integer keys with fixed digits) — not pure comparison sorts.linear-time
- 10Which common O(n log n) sorts are stable?Mergesort is the standard stable O(n log n) example; heapsort/quicksort typically are not.stability