Lesson 23 — Quicksort
Quicksort: pick a pivot, split, repeat
Quicksort is a divide and conquer sort: pick a pivot value, split the list into items smaller than it, equal to it, and bigger than it, then sort the two outer parts the same way (recursion). Lists of length 0 or 1 are already sorted — the base case.
small = [n for n in nums if n < pivot]
On average it runs in O(n log n) — far faster than bubble sort on big data.
Why it matters: variants of quicksort sit inside many standard libraries' sort functions.
Fill in left, mid and right with list comprehensions. Expected: [1, 2, 5, 5, 6, 9].
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Algorithms Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Algorithms Foundations books — check the publication year so the examples match current versions.
Search Amazon →