Dutch National Flag
Three pointers sort the array into less, equal and greater in one pass.
Decision · step 2 of 10Rotate, Partition, Select: Sort into less, equal, greater
2 is larger than 1, so it swaps up to index 7. High moves down, but mid stays: the value that came back is still unknown.
What you will see
Three regions grow from the ends and the middle; the scanning pointer routes each value.
Cost
| Best | O(n) |
|---|---|
| Average | O(n) |
| Worst | O(n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Each cell is announced as index, value and state; each step's accessibility text states the decision and its effect.
Reduced motion: Swaps and shifts become value crossfades with an outline flash; pointers appear at their destination.
Before this
Related
Taught by the same lesson
Rotate, Partition, Select covers these too, in the same run.