Sorting Algorithms
Implement and compare the main sorting algorithms and use sorting with key functions as a preprocessing step.
3 objectives 6 steps about 125 min
Check what you know
The lessons are coming later. The knowledge check is ready now.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Implement insertion sort, merge sort and quicksort with in-place partitioning, and state each one's best and worst time, extra space and stability.
- Explain the n log n lower bound for comparison sorting and identify inputs where counting or radix sort beats it.
- Sort records by multiple keys with sorted() and key functions, relying on stability, and recognize problems that become simple once the input is sorted.
Lesson plan
6 steps, about 125 min · 0 of 5 lessons available so far
- Insertion Sort and Its Invariant Concept · 15 min · coming later
- Merge Sort, Line by Line Worked example · 25 min · coming later
- Partitioning: Quicksort and Quickselect Worked example · 25 min · coming later
- Beating n log n with Counting and Radix Sort Concept · 20 min · coming later
- Lab: Multi-Key Sorts and Sort-First Solutions Lab · 25 min · coming later
- Check: Choose and Justify a Sort Knowledge check · 6 questions
Practise it
Implement merge sort and randomized quicksort, verify both against sorted() with randomized tests, benchmark them on random, already-sorted and many-duplicate inputs, and explain the quicksort result on the duplicate-heavy case.
Build it from scratch
Practice builds that exercise this skill by re-creating a real technology.
References
Hard prerequisites
Unlocks
On these roadmaps
Progress and evidence for this skill are shared across all of them.