
Nupur P.
asked 02/03/21Find a Python implementation of Selection Sort (or write your own). add line numbers. Then trace the execution through at least two iterations of the outer loop, use test array
test array example:
array = [6,3,8,2,9,5,1]
1 Expert Answer

Patrick B. answered 02/03/21
Math and computer tutor/teacher
def SelectionSort( array, N):
for iLoop in range(int(N)):
min=array[iLoop]
indexOfMin=iLoop
for jLoop in range(int(iLoop),int(N)):
if (int(array[jLoop])<int(min)):
min = array[jLoop]
indexOfMin=jLoop
print("smallest is " + str(min) + " found at index " +str(indexOfMin))
print(" swapping with " + str(array[iLoop]) + " at index " + str(iLoop) )
temp = array[iLoop]
array[iLoop]=array[indexOfMin]
array[indexOfMin]=temp
return(array)
array = [6,3,8,2,9,5,1]
SelectionSort(array,7)
print(array)
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
source code posted in RESOURCES section under this link02/03/21