150k views
2 votes
Consider the following list. list = {24, 20, 10, 75, 70, 18, 60, 35} Suppose that list is sorted using the selection sort algorithm as discussed in the book. What is the resulting list after two passes of the sorting phase; that is, after two iterations of the outer for loop? list = {10, 18, 24, 20, 75, 70, 60, 35} list = {10, 18, 20, 24, 75, 70, 60, 35} list = {10, 18, 24, 75, 70, 20, 60, 35} list = {10, 20, 24, 75, 70, 20, 60, 35}

1 Answer

3 votes

Answer:

list = {10, 18, 24, 75, 70, 20, 60, 35}

Step-by-step explanation:

Selection is a sorting algorithm that will set a cursor position and search for a minimum number from the list. When the minimum number is found, that minimum number will be swapped with the number in the cursor position. Only one number will be swapped and sorted in one iteration of outer loop. To sort the next number in the following outer loop iteration, the cursor will be moved to the next position and repeat the same search and swapping process as in the first iteration. When finishing all the iterations of outer loop, all numbers shall be sorted in ascending order.

User Mike Mozhaev
by
3.4k points