Data Structures & AlgorithmsHard

A top-down merge sort splits a range of size n into floor(n/2) and ceiling(n/2) parts and stops at size 1 or 0. Counting the root call, how many calls are made in total when n = 10?

  1. A. 20
  2. B. 31
  3. C. 10
  4. D. 19

Correct answer: D. 19

Every range of size ≥ 2 splits into two non-empty halves, so the call tree is a full binary tree with n leaves and 2n − 1 = 19 nodes. 20 is 2n, 10 counts only the leaves, and 31 pads n up to 16 as if it had to be a power of two.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic