ProLesson 2 of 37 min read

Merge sort: split the list, then merge it back in order

See step by step how merge sort breaks a list into tiny pieces and merges them back together in sorted order.

Binary search is fast, but only on sorted data. So we need a good way to sort. Simple methods, like repeatedly swapping neighbours that are out of order, are easy to write but slow down badly on large lists. Merge sort is a classic method that stays efficient as lists grow, and it is built on one neat idea: merging two lists that are already sorted is easy.

Vidi Pro

Keep going with Pro.

The first lesson of every class is free. Pro opens every lesson in IELTS, Programming, Mathematics, Science and Data and AI, with practice questions.

Already have Pro? Log in to keep reading.

Written with AI help. Spotted a mistake? Tell us.