Questions: Quicksort

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer implements quicksort using the first element as pivot, then runs it on 10,000 names already in alphabetical order. What is the likely time complexity, and why?

AO(n log n) — sorted input is the best case for quicksort
BO(n²) — the pivot is always the minimum, producing maximally unbalanced partitions
CO(n) — the partition step recognizes the array is sorted and skips work
DO(n log n) regardless — quicksort's performance doesn't depend on pivot choice
Question 2 Multiple Choice

Quicksort and merge sort both have O(n log n) average-case complexity. In practice, quicksort is often faster on large arrays. What best explains this?

AQuicksort makes fewer comparisons than merge sort in all cases
BQuicksort operates in-place on a contiguous memory block, producing better CPU cache performance
CQuicksort's recursion is shallower because it uses three-way partitioning by default
DMerge sort has O(n²) worst case, making its average performance slower
Question 3 True / False

Randomized quicksort achieves O(n log n) expected running time on any input, but this is a probabilistic expectation — not a worst-case guarantee.

TTrue
FFalse
Question 4 True / False

Quicksort is called 'in-place' because it requires no additional memory beyond the input array, giving it O(1) space complexity.

TTrue
FFalse
Question 5 Short Answer

Explain why choosing the first element as pivot performs poorly on already-sorted arrays, and how randomized pivot selection fixes this.

Think about your answer, then reveal below.