Analyzing skipped merges

An invoice system sorts the identifiers


[101,102,103,104,105,106,107,108,116,115,114,113,112,111,110,109][101,102,103,104,105,106,107,108,116,115,114,113,112,111,110,109]


using this modified top-down merge sort:

  • Split each non-singleton section into equal contiguous halves and recursively sort both halves.
  • After both halves return, perform exactly one boundary key comparison: is the left half's last value less than or equal to the right half's first value?
  • If yes, leave the section unchanged, with no merge and no temporary-buffer writes.
  • If no, perform a standard ascending merge. Compare current front keys until one input is exhausted, then copy the leftovers. Write every item in that section to the temporary buffer exactly once.

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.

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: