October 2025
Intermediate to advanced
485 pages
13h 2m
English
Assume that we want to sort the array [8, 4, 3, 7, 6, 1, 2, 5]. Note that this is not the type of array whose two halves are already sorted. In fact, it’s a complete mess.
Step 1: First, we make copies of the two halves of the array:

Step 2: We recursively perform Mergesort on the left copy. In code, this would be written as mergesort([8, 4, 3, 7]). This, in turn, will make copies of the two halves of [8, 4, 3, 7]:

Step 3: We recursively perform Mergesort on the left copy (which I’ll call left half going forward). This means ...
Read now
Unlock full access