Count comparisons
Warm-up · Trace the algorithm · about 4 min
Selection sort runs on [6, 3, 8, 1, 9, 2]. Count its comparisons, first in pass 1 and then in total.
Example 1
Input:
{"values":[6,3,8,1,9,2]}
Output:
15
Constraints
- Answer with a whole number.
- A comparison checks one value against the current min.
Learn the idea first: Selection sort, a visual lesson.
More Selection sort problems
- State after two passes Warm-up
- Is selection sort stable? Standard
- Implement selection sort Standard
- The k smallest values Standard
- Selection sort of pairs by key Challenge