Getting your lesson ready…

0
Reading your lesson…
0:00 / 0:00

How does merge sort put a list in order by splitting and joining?

A lesson on sorting. Computing, secondary school level.

Merge sort orders a list by splitting it in half again and again until every piece holds one item, which is already sorted.

Then it joins pieces in pairs.

To merge two sorted pieces, it compares their first items, takes the smaller, and repeats until both are empty.

Take the list 5, 2, 4, 1.

It splits into 5 and 2, and 4 and 1, which merge into 2, 5 and 1, 4.

Comparing their fronts gives 1, then 2, then 4, then 5.

Each round of merging touches every item once, so sorting stays fast even for long lists.

Questions in this lesson