Merge sort (von Neumann)
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:
- True or false. A single-element vector is sorted by definition.
- True or false. Merge sort begins by recursively dividing its input into smaller vectors.
- True or false. The input to the merge function is two unsorted vectors.
- True or false. Merge sort is not a stable sorting algorithm.
- 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ɹʇ
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.