Records arrived in the order A,B,C,DA,B,C,DA,B,C,D, with numerical keys 4,9,4,124,9,4,124,9,4,12, respectively. During an ascending merge sort, the final sorted halves are [(4,A),(9,B)][(4,A),(9,B)][(4,A),(9,B)] and [(4,C),(12,D)][(4,C),(12,D)][(4,C),(12,D)].
The merge selects the right record whenever the current keys are equal. Assume all other merge operations are implemented correctly using the standard array method. Select every true statement.
Selecting from the left on equality at every merge preserves arrival order.
Selecting from the right on equality makes worst-case running time linear.
The merge preserves arrival order because both input halves are internally stable.
The resulting keys remain in nondecreasing order despite the equality rule.
Unlock full course notes by signing up
Finding records lost after the merge loop
A program merges two sorted lists of ticket numbers. A tail is the portion of an input that has not yet been consumed. The following Python function contains a bug:
Trace the function with left = [2, 7, 11] and right = [4, 6, 10, 13, 15]. The incomplete output contains ________ ticket numbers. At termination, an unconsumed tail remains in the ________ input and contains ________ ticket numbers.
Splitting array ranges precisely
A merge-sort implementation sorts portions of a sensor-reading array without copying subarrays. Each portion uses a half-open range: it includes the start index and excludes the stop index. A range starting at index sss and stopping at index ttt therefore contains t−st-st−s readings.
For each recursive split, calculate the middle index using
Analyzing skipped merges
An invoice system sorts the identifiers
using this modified top-down merge sort:
Tracking buffers that coexist during recursion
A small device uses recursive merge sort to arrange 40 measurement records. Its implementation allocates temporary buffers as follows:
An invocation with zero or one record returns immediately without allocating a buffer.
An invocation with n≥2n\geq2n≥2 records first allocates a buffer containing exactly nnn record slots.