229k views
2 votes
Which of the following correctly shows the iteration of an ascending sort (from left to right) using the selection sort algorithm on an array with the following elements: {10, 6, 3, 2, 8} Select one: a. {2, 6, 3, 10, 8), (2, 3, 6, 10, 8), (2, 3, 6, 10, 8), 2, 3, 6, 8, 10) C b. {6, 10, 3, 2, 8}, {3, 6, 10, 2, 8}, {2, 3, 6, 8, 10) c. {2, 6, 3, 10, 8}, {2, 3, 6, 10, 8}, {2, 3, 6, 8, 10} d. {6, 10, 3, 2, 3, (3, 6, 10, 2, 8}, {2, 3, 6, 10, 8}, {2, 3, 6, 8, 10} 2 o

User Elmazzun
by
8.5k points

1 Answer

4 votes

Answer:

The correct answer is c. {2, 6, 3, 10, 8}, {2, 3, 6, 10, 8}, {2, 3, 6, 8, 10}.

Step-by-step explanation:

The selection sort algorithm works by finding the smallest element in the unsorted part of the array and swapping it with the first element of the unsorted part. This process is repeated until the entire array is sorted.

In the given array {10, 6, 3, 2, 8}, the smallest element is 2. So, it is swapped with the first element 10 to get {2, 6, 3, 10, 8}. Next, the smallest element in the unsorted part (which is {6, 3, 10, 8}) is 3. So, it is swapped with the second element 6 to get {2, 3, 6, 10, 8}. The process is repeated until the entire array is sorted, resulting in {2, 3, 6, 8, 10}.

User Ravenspoint
by
8.4k points