A Quick Sort implementation chooses a pivot uniformly at random from each active range, moves it to the last position, and partitions using a strict less-than test. It then makes two ordinary recursive calls, excluding the pivot, and returns immediately for ranges of size zero or one.
Which statements about sorting nnn keys are correct? Select every correct statement. Count comparisons between scanned keys and pivots, excluding pivot-selection work.
For distinct keys, random pivot selection gives an expected comparison count of Θ(nlogn)\Theta(n\log n)Θ(nlogn) over the algorithm's random choices.
For distinct keys, random pivot selection guarantees a comparison count of Θ(nlogn)\Theta(n\log n)Θ(nlogn) on every execution of the algorithm.
For identical keys, this strict less-than partition gives a comparison count of Θ(n2)\Theta(n^2)Θ(n2) despite selecting each pivot randomly.
For any keys, constant auxiliary storage inside partition guarantees constant total auxiliary storage for the complete recursive sorting algorithm.
Unlock full course notes by signing up
Counting comparisons on ordered records
A program uses Quick Sort to sort 121212 distinct record identifiers that are already in increasing order. Every partition selects the last key, scans each other key once using a strict less-than test, and then recursively sorts the two sides. Ranges containing zero or one key return immediately.
How many comparisons between scanned keys and pivots occur during the complete sort? Exclude index tests and pivot-selection work. Enter an integer count, to zero decimal places.
Sizing three-way recursive ranges
A warehouse sorts batches of packages by integer priority key. A three-way partition separates a range into records below the pivot key, records equal to it, and records above it. Quick Sort then sorts only the below-pivot and above-pivot ranges. The entire equal-key block, including the chosen pivot record, is excluded from further recursive sorting.
The table gives all key frequencies for three separate batches. A frequency is a count of records, and the selected pivot record is already included in that count.
Complete the table with exact integer counts. Report both recursive range sizes and the number of records excluded in the equal-key block. Count every record equal to the pivot, not just the chosen pivot record.
Separating comparisons, calls, and depth
A Quick Sort execution sorts 111111 distinct job-priority scores. Each partition compares every non-pivot key with the pivot once and excludes the pivot from subsequent ranges. The pivot choices have these ranks within their active ranges:
In the eleven-key range, the pivot is the fourth-smallest key.
In the seven-key range, the pivot is the middle key, leaving three keys on each side.
Building a Quick Sort correctness proof
A Quick Sort implementation receives records with distinct keys. It returns immediately for a range of length zero or one. Otherwise, its partition operation preserves every record and produces a left range with keys smaller than the pivot and a right range with keys larger than the pivot. It recursively sorts those two ranges and leaves the pivot between them.
You are proving that this algorithm returns the original records in increasing key order using strong induction. For an arbitrary length n≥2n\geq2n≥2, the inductive hypothesis is the assumption that the algorithm is correct for every input length smaller than nnn.
Arrange the proof statements into a coherent outline. Start with the base cases, establish that the hypothesis applies before using it, and end with the conclusion for every input length. The hypothesis is available only for smaller ranges.