A small device uses recursive merge sort to arrange 40 measurement records. Its implementation allocates temporary buffers as follows:
Here, peak temporary-buffer storage means the largest total number of allocated buffer slots at any instant. Exclude the input array and all function-call bookkeeping from that total.
Find both the peak temporary-buffer storage, in record slots, and the maximum number of simultaneously active merge-sort invocations. For the invocation count, include the original call and any base-case call; a waiting parent remains active on the call stack. Give both answers as exact integers.
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
Analyzing skipped merges
An invoice system sorts the identifiers
using this modified top-down merge sort: