Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the SelectionSort algorithm (list L; positive integer j ) Recursively sort

ID: 3195032 • Letter: U

Question

Using the SelectionSort algorithm (list L; positive integer j ) Recursively sorts the items from 1 to j in the list L into increasing order

If j=1 then

Sort is complete, write out the sorted list

else

Find the index I of the maximum items in L between 1 and j

Exchange L[i] and L[j]

SelectionSort(L, j-1)

end if

end function SelectionSort

simulate the execution of the algorithm on the following list L; write the list after every exchange.  

L:    5, 4, 9, 6, 8

_______________

_______________

_______________

Explanation / Answer

In case of doubt, please don't hesitate to write back to me:

N-1 passes where n= no of items

So, here we require 5-1 = 4 passes. Lets see what those passed will be

L: 5 4 9 6 8

1. A selection sorts finds the minimum, and then replaces the first digit if it not the smallest with the smallest

After :

Iteration1: 4 5 9 6 8

2. Then it does the same with 2nd digit:

Iteration2: 4 5 9 6 8

3.Iteration3: 4 5 6 9 8

4. Iteration4: 4 5 6 8 9

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote