Quicksort
Quicksort is an interactive experiment in Algorithms Visualised, a free simulation from StudyFi Lab that runs right in your browser.
Quicksort picks a pivot — here the last element of the range (Lomuto partition) — and rearranges the range so that smaller elements go left and the rest go right. The pivot then sits in its final place, and both parts are sorted the same way. On average it is O(n log n), but when the pivot splits badly (for example on an already sorted or reversed array) it drops to O(n²).
Try this: Compare random input with reversed input. On the reversed array the pivot is always the largest or smallest — watch the comparisons jump.
Frequently asked questions
What does the “Quicksort” experiment show?
Quicksort picks a pivot — here the last element of the range (Lomuto partition) — and rearranges the range so that smaller elements go left and the rest go right. The pivot then sits in its final place, and both parts are sorted the same way. On average it is O(n log n), but when the pivot splits badly (for example on an already sorted or reversed array) it drops to O(n²).
How do I try “Quicksort”?
Compare random input with reversed input. On the reversed array the pivot is always the largest or smallest — watch the comparisons jump.
Studying for a test?
Upload your notes and StudyFi turns them into flashcards, tests and podcasts.