Home › Learn › World 5: Sorting Factory
PREMIUMOverload Foreman
Quick sort, O(n log n) average
World 5 boss of Code the Hero, in Sorting Factory: selection, insertion, merge and quick sort.
What you practise
Quick sort, O(n log n) average. You write real Python, Java or JavaScript, press Run, and the hero acts out every line, so you can see why the fast way is fast.
Boss: Overload Foreman. Beat it to restore Sorting Factory.
What it costs
| Average | O(n log n) |
| Worst | O(n²) |
| Extra space | O(log n) stack |
How the stars are earned
- Sorted on every test
- At most n² comparisons
- At most 2·n·log₂n comparisons
Your code is also checked on hidden inputs, so it has to work for any case, not only the one on screen.
Worlds 1–3 (21 levels) are free. Sorting Factory is part of Premium.
More in Sorting Factory
- Selection Belt: Selection sort, O(n²) compares, ≤ n swaps
- Insertion Belt: Insertion sort, fast on nearly sorted data
- Merge Press: Merging two sorted lists, O(n + m)
- Merge Sort Line: Merge sort, O(n log n)
- Pivot Crane: Partitioning around a pivot, O(n)
- Colour Bins: Dutch national flag, one pass