Count comparisons separately from array writes

A device sorts six measurement records by their integer keys using ascending selection sort. Initially, the keys are 5, 1, 4, 2, 3, 6, in that order. Each of five passes initializes the candidate at the pass boundary and compares every later key with the candidate, updating the candidate only for a strictly smaller key. There is no early exit.


Implementation C exchanges entries only when the selected position differs from the boundary. Implementation U executes an exchange at the end of every pass, including when both positions are the same.


An array write means one assignment to an array position. Count exactly two array writes for every executed exchange, even an exchange with the same position; ignore assignments to local variables and any compiler optimizations.


Enter three exact integer counts: key comparisons made by either implementation, array writes made by C, and array writes made by U. Count only key comparisons, not index or loop-condition checks.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Selection Sort Questions: