previous |
start |
next
Analyzing the Performance of the Selection Sort Algorithm
- To analyze the selection sort algorithm, we
will count how often an array element is
visited.
- For a vector with n elements, we must
visit all n of them to find the smallest one. Then visit two
elements to swap them.
- In the next step, we visit n - 1
elements to find the minimum, plus two elements to
swap.
- In the next step, we visit (n - 2) + 2
elements.
- The total elements visited is

because

previous |
start |
next