Algorithms and OOD (CSC 207 2014S) : EBoards

CSC207.01 2014S, Class 28: Quicksort


Overview

Preliminaries

Upcoming Work

Admin

Aspects of QuickSort

So what is the pivot?

Is QuickSort stable?

More importantly, it's memory efficient.

Practice:

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.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.