Brainlag
  1. Python
  2. Problem solving
40/42 lessons

Sorting by hand

35 min4 exercisesPremium

Write insertion sort and merge sort yourself in Python, test them against sorted(), and see why one is O(n^2) and the other O(n log n).

The skill
Write two classic sorting algorithms, test them against sorted(), and explain why one scales and the other does not.
You make
An insertion sort, a merge for two sorted playlists and a merge sort for song lengths.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 39 Functions that call themselves. Free to try: Python Foundations and the playground.

Step 1 of 7
exercise_1.py

You've reached the good stuff.

4 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

Python 3.13