An invoice system sorts the identifiers
using this modified top-down merge sort:
A temporary-buffer write places one item into that buffer. Do not count copying the buffer back to the array, index checks, or loop checks. Single-item calls perform no key comparisons or buffer writes.
Find the total number of key comparisons, including boundary comparisons, and the total number of temporary-buffer writes. Give both as exact integer counts.
Unlock full course notes by signing up
Separating sortedness from stability
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.
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
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.