Question: Activity 4 . 5 . 2 : Selection Sort Consider the following algorithm on an array of numbers x 1 , x 2 , x
Activity : Selection Sort
Consider the following algorithm on an array of numbers x x x xn
The element in the first position is compared to the n remaining elements; whenever one is found that is less, the first element is swapped with it Then the element in the second position is compared with the remaining n elements. Whenever one is found that is less, the elements are swapped. This continues until the nst element; if it is out of order with the nth element, the elements are swapped. The algorithm pseudocode is shown below:
The selection sort algorithm
Step through this algorithm when applied to the array x x x x Record the values of the array every time they change.
In terms of n how many comparisons does this algorithm make on an array of length n
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
