Space Complexity O(n)
def SelectionSort(arr):
arr1=[]
for i in range(len(arr)):
mini=min(arr)
arr1.append(mini)
arr.remove(mini)
print (arr1)
print (SelectionSort(array))
Space Complexity O(1)
array = [251,64,12,22,11]
# #first loop i=0
# mini=min(array)
# arr1.append(mini)
# arr.remove(mini)
# print(array)
# # #second loop i=1
# # mini=arr.min
# # arr1[1]=mini
# # arr.remove(mini)
def SelectionSort(arr):
for i in range(len(arr)):
for j in range(i+1,len(arr)):
mini_index=i
if arr[j]<arr[mini_index]:
mini_index=j
temp=arr[mini_index] #do the swap
arr[mini_index]=arr[i]
arr[i]=temp
print("I swapped {} with {}".format(arr[i],arr[mini_index]))
print (arr)
return arr
print (SelectionSort(array))