Quick sort: pivot and partitioning
Picks a pivot, splits the list into items smaller and larger than the pivot, then sorts each part the same way (recursion) until the parts are sorted.
Understanding Quick sort: pivot and partitioning in VCE Software Development U3O1
What it does: The function calls itself on the smaller and larger parts, then joins them with the pivot in the middle. Without this base case the function would keep calling itself forever. A short list needs no sorting. The pivot can be any item (first, last, middle or random). Every other item is compared to it to decide which part it goes in. Divide and conquer breaks a big list into smaller lists, then sorts each smaller list using the same method (recursion). The pivot is 5. Items less than 5 are 2 and 1. Items greater than 5 are 8 and 9.
Common mistakes: The pivot must be one item from the list, so it should be pivot = items[0]. Writing pivot = items makes the pivot the whole list, so it can't be compared with single items. The base case must stop when the list has 0 or 1 items, so it should be if len(a) <= 1:. With >= almost every list returns early without being sorted, and an empty list never stops the recursion.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 142–155) and word search (Modules 142–166).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
quick sortFill in the Blanks
Spot the Error
Student with a class code? Join your class →