Python Quest

Track 16 · Lesson 4 of 12

Sorting algorithms

Understand how selection, insertion and merge sort work and what they cost, then use sorted() with stable keys in practice.

About 50 minIntermediate4 exercises

You will be able to

  • Trace selection sort and insertion sort and explain why they are O(n²)
  • Merge two sorted lists in linear time and build merge sort from that step
  • Explain what a stable sort is and use stability to sort by several criteria
  • Choose sorted() or list.sort() with a key function for real work

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.