SELECTION SORT
Selection sort is an in-place sorting algorithm. This sorting technique improves over
bubble sort by making only one exchange in each pass.
The selection sort finds the smallest element in the list and it is swapped with the first
element in the list.
Then the second smallest element is searched and it is swapped with the second
element in the list.
This selection and exchange process continues, until all the elements in the list have
been sorted in ascending order.
This algorithm is called selection sort since it repeatedly selects the smallest element.
Algorithm
1. Find the minimum value in the list
2. Swap it with the value in the current position
3. Repeat this process for all the elements until the entire array is sorted.
Implementation
def selectionsort(A):
for i in range(len(A)):
minimum=i
for j in range(i+1,len(A)):
if A[j]<A[minimum]:
minimum = j
swap(A,minimum,i)
def swap(A,x,y):
temp=A[x]
A[x]=A[y]
A[y]=temp
A=[54,26,93,17,77,31,44,55,20]
selectionsort(A)
print(A)