Algorithms and OOD (CSC 207 2014S) : EBoards
So what is the pivot?
Is QuickSort stable?
More importantly, it's memory efficient.
Let's organize this array:
[slots are numbered 0 – 11] lb = 0; ub = 12 a|l|p|h|a|b|e|t|i|c|a|l [we pick b as our pivot] lb = 1; ub = 12 b|l|p|h|a|a|e|t|i|c|a|l
If an element is > b we lower ub, if element is < b we raise lb
We keep sorting, get to
a|a|a|b|h|e|t|i|c|p|l|l ub == lb == 3
So we recurse over the first four elements and the rest of the list, and the list is eventually sorted!
Copyright (c) 2013-14 Samuel A. Rebelsky.
This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.