Merge sort (von Neumann)

Published

2023-08-05

Merge sort is entirely different than the sorting algorithms we’ve seen so far, and it represents an important class of algorithms—divide-and-conquer algorithms. Divide-and-conquer algorithms work by breaking a problem down into smaller subproblems, solving the subproblems, and then building a complete result from the solved subproblems. Merge sort uses recursion to do this.

Here we implement merge sort in C++.

Additional resources:

Comprehension check:

  1. True or false. A single-element vector is sorted by definition.
  2. True or false. Merge sort begins by recursively dividing its input into smaller vectors.
  3. True or false. The input to the merge function is two unsorted vectors.
  4. True or false. Merge sort is not a stable sorting algorithm.
  5. Given two input vectors 3, 5, 7 (left) and 1, 8, 9 (right), the merge function would consume elements from these vectors in the sequence right, left, ______, ______, ______, right.

Answers: ʇɥƃᴉɹ / ʇɟǝl / ʇɟǝl / ǝslɐɟ / ǝslɐɟ / ǝnɹʇ / ǝnɹʇ

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.