Free tools Windows power users keep installed
One-click scans. No signup required.
Merge sort orders a list by splitting it into smaller parts, sorting those parts, and merging them back together. For the standard array implementation, it takes Θ(n log n) time when comparisons take constant time, uses Θ(n) extra memory, and is stable when equal items are taken from the left run first.
How merge sort works
The algorithm has two jobs: recursively produce sorted halves, then combine each pair of sorted halves into a larger sorted run. Splitting alone does not sort the items; the merge step is what puts them in order.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Introduction to Algorithms, fourth edition | $99.47 | Buy on Amazon |
| 2 |
|
Algorithms (4th Edition) | $68.77 | Buy on Amazon |
| 3 |
|
Algorithm Design | $223.83 | Buy on Amazon |
| 4 |
|
Introduction to Algorithms, 3rd Edition | $90.43 | Buy on Amazon |
| 5 |
|
The Algorithm Design Manual (Texts in Computer Science) | $48.64 | Buy on Amazon |
As an Amazon Associate I earn from qualifying purchases.
1. Divide the array
Split the array into two halves, continuing until each part has one item. A one-item run is already sorted. If the array length is odd, the halves can differ in size by one.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute2. Sort each half
Apply the same process to each half. Once the smaller runs have been sorted, their results are ready to merge.
#1 Best Overall
- color: White
- INTRODUCTION TO ALGORITHMS, FOURTH EDITION
3. Merge the sorted runs
Keep a pointer at the start of each run. Compare the pointed-to items, write the smaller one to the output, and advance that run’s pointer. Repeat until one run is empty, then copy the remaining items from the other run. Because each input run is already ordered, repeatedly choosing the smaller next item produces one ordered run.
For example, merging [2, 7] and [3, 6] proceeds by writing 2, then 3, then 6, then the remaining 7, producing [2, 3, 6, 7]. A merge examines each item at most as it advances through the runs, so its work is linear in the number of items being merged.
Rank #2
Why merge sort takes Θ(n log n) time
At each level of splitting, the runs together contain n items, and merging them takes Θ(n) work. Splitting in half creates about log₂ n levels before the runs reach one item. Multiplying Θ(n) work per level by Θ(log n) levels gives Θ(n log n) total time.
Equivalently, the recurrence is T(n) = 2T(n/2) + Θ(n): two recursive sorts handle half the items each, followed by a linear merge. This bound assumes constant-time comparisons. Princeton’s official Mergesort (Section 2.2) page describes the guarantee as time proportional to N log N regardless of input; NIST also lists merge sort’s runtime as Θ(n log n) in its merge sort reference.
Rank #3
Is merge sort stable?
Yes, if the merge handles ties correctly. A stable sort keeps records with equal sort keys in the same relative order they had in the input. During a merge, when the next items from both runs compare equal, take the item from the left run first. That preserves the original order across the two runs. Princeton documents stability for its top-down Merge implementation and its bottom-up MergeBU implementation.
How much extra memory does it use?
The standard array implementation needs Θ(n) auxiliary storage for merging: it uses temporary space to combine the runs rather than rearranging everything solely within the original array. In its ordinary form, this is not an in-place array sort. Princeton’s documented top-down and bottom-up array implementations both specify Θ(n) extra memory.
Rank #4
The trade-off is predictable running time and stability at the cost of temporary storage and additional memory traffic while items are copied and merged.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Top-down and bottom-up merge sort
These are two ways to schedule the same basic merge work. The cited Princeton implementations have the same asymptotic time, stability, and auxiliary-memory bounds; neither is universally faster on that evidence.
Best Value
| Form | How it proceeds | Recursion | Documented bounds |
|---|---|---|---|
| Top-down | Splits the array recursively, then merges the sorted halves. | Recursive | Θ(n log n) time with constant-time comparisons; stable; Θ(n) extra memory. |
| Bottom-up | Starts with one-item runs and merges neighboring runs in successively larger groups. | Non-recursive | Θ(n log n) time; stable; Θ(n) extra memory. |
Choose the recursive form when its divide-and-conquer structure makes the implementation easier to follow. A bottom-up form avoids recursive calls, which can suit implementation requirements that favor iteration. The documented implementations do not establish a general speed advantage for either form.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What library implementations can change
The Θ(n log n) analysis describes the standard merge-sort approach, not every built-in sort. Libraries may use tuned or adaptive implementations, so check the documentation for the language and version in use.
For example, the Java SE 24 Arrays documentation describes its object-array implementation as a stable, adaptive, iterative mergesort. It notes that nearly sorted input can require approximately n comparisons, while temporary storage varies with the input. This is a version-specific implementation note, not a claim about every Java version, primitive-array sort, or other language’s built-in sorting method.
Further reading
For a broader treatment of sorting and algorithms, Princeton’s Algorithms, 4th Edition booksite identifies sorting, including mergesort, in Chapter 2 and provides associated online materials.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




