A print queue contains jobs in arrival order [4A, 2A, 4B, 2B, 1C]. Each number is a priority; each letter identifies a job within that priority. A stable sort preserves arrival order among jobs with equal priorities.
The queue uses ascending selection sort. Each pass starts with the first remaining job as its minimum candidate, replaces that candidate only for a strictly smaller priority, and finally swaps the selected job with the first remaining job. Comparisons ignore the letters. Which statements are true? Select all that apply.
The priority-4 jobs finish in reversed arrival order, so this implementation fails to preserve stability.
The priority-2 jobs retain their arrival order even though this implementation fails to preserve stability.
Both repeated-priority groups finish in their arrival order because each swap moves only the selected minimum.
Strictly smaller comparisons guarantee stability because a later equal minimum never replaces the current candidate.
Unlock full course notes by signing up
Repair two selection-sort loop errors
A student writes the following Python code to sort an array A of n distinct integers in ascending order, where n is at least 2. Python uses zero-based indexing, and range excludes its stop argument.
Complete both repairs so the program correctly sorts every permitted input. Move the initialization of min_index to the beginning of the outer-loop body and assign it ________. Change the inner range's stop argument from n - 1 to ________. Keep the remaining code unchanged.
Count comparisons separately from array writes
A device sorts six measurement records by their integer keys using ascending selection sort. Initially, the keys are 5, 1, 4, 2, 3, 6, in that order. Each of five passes initializes the candidate at the pass boundary and compares every later key with the candidate, updating the candidate only for a strictly smaller key. There is no early exit.
Implementation C exchanges entries only when the selected position differs from the boundary. Implementation U executes an exchange at the end of every pass, including when both positions are the same.
An array write means one assignment to an array position. Count exactly two array writes for every executed exchange, even an exchange with the same position; ignore assignments to local variables and any compiler optimizations.