Mathematics I / Searching and Sorting
Practice question · Put in order

Order the steps of merge sort on a list.

Hints
  1. Divide and conquer: split, solve the pieces, then combine.
  2. Merging is only cheap because both halves are already in order.
Show the answer
  1. Split the list into two halves
  2. Sort the left half by the same method
  3. Sort the right half by the same method
  4. Merge the two sorted halves into one sorted list
  5. Return the merged list
Why

Splitting costs nothing, the two halves are sorted recursively, and the merge is a single linear pass because each half is ordered. The splitting depth is logarithmic and each level costs a linear merge, which is where the linearithmic total comes from.

Read the lesson: Searching and Sorting →

Practise Searching and Sorting

The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.

More questions on Searching and Sorting