Analyzing Selection Sort

Objective: Count how many times cards are handled when you sort n cards. (Call this H(n))

n + (n-1) + (n-2) + ... + 1

is at most n2 and at least n2/4 (n/2 of the numbers are n/2 or larger). So:

n2/4 ≤ H(n) ≤ 2n2

(Factor of 2 on the upper bound because each card is handled one or two times.)