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\geq2 records first allocates a buffer containing exactly nn record slots.
  • It then sorts the left child completely, followed by the right child. The left child has ⌊n/2⌋\lfloor n/2\rfloor records; the right child has the remaining records.
  • It merges the children using its buffer, releases that buffer, and returns.
  • A parent's buffer remains allocated throughout both child calls. A child's buffer is released before that child returns. Subarrays are passed as index ranges, so no other record arrays are created.


A flowchart shows the buffer lifetime within a non-base merge-sort invocation.


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.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Merge Sort Questions: