CS 411 Fall 2025  >  Outline & Supplemental Notes for September 29, 2025


CS 411 Fall 2025
Outline & Supplemental Notes
for September 29, 2025

Outline

Divide and Conquer [L Ch 5 intro]

Merge Sort [L 5.1]

Supplemental Notes

Merge Sort Space Usage

Merge Sort’s worst feature is its space usage. A recursive version has recursion depth \(\Theta(\log n)\); it thus requires \(\Theta(\log n)\) additional space. More importantly, a general-purpose fast Stable Merge algorithm requires a separate buffer large enough to hold all of the input: \(\Theta(n)\) additional space. It is apparently possible to do a Stable Merge on an array in-place; however, the algorithms to accomplish this are far slower than the one that uses an extra buffer. We therefore generally think of Merge Sort as an algorithm requiring linear additional space.

In certain cases, both of the above space requirements can be eliminated. Merge Sort only modifies its data in the Stable Merge operation. We can thus think of Merge Sort simply as a sequence of Stable Merge calls. Furthermore, given the size of the input (\(n\)), we know exactly what Stable Merge calls will be done; these do not depend on the values of data items. As a result, the Stable Merge calls can be done in a bottom-up manner without using recursion. First we merge sequences of size \(1\) into sequences of size \(2\). Then we merge sequences of size \(2\) into sequences of size \(4\), and so on. This iterative Merge Sort eliminates the \(\Theta(\log n)\) additional space requirement of the recursive version.

But even an iterative Merge Sort still requires an extra buffer of size \(\Theta(n)\) for the Stable Merge operation, if the general-purpose version of Stable Merge is used. However, for a Linked List, Stable Merge can be done in-place (\(\Theta(1)\) space). Therefore, we can write an in-place iterative Merge Sort for a Linked List.