Selection sort in python.





Selection sort is the simplest sorting method in data structure,This sorting algorithm is compression based algorithm in which is dividing the data set in two part,the sorted part at the left side and unsorted part at the right side,the sorted part is empty and unsorted part is entire data set,The smallest element is selected from to the unsorted dataset,and the swipe to the left side,and that element becomes a part of the sorted data set.This process continues moving the element to the left side,The first position where 5 is stored presently,we search the whole data set and find the lowest value in side the data set.So we replace 5 with 1.which happens to be the minimum value in the list, in the first position of the sorted list.Doing this process continuously,The same process is applied to the rest of the items in the data set.


Code:

arr=[9,8,7,6,5,4,3,2,1,0,55];
for i in range(len(arr)):
    max_idx=i;
    for j in range(i+1,len(arr)):
        if arr[max_idx]>arr[j]:
            max_idx=j; 
    arr[i],arr[max_idx]=arr[max_idx],arr[i];
for i  in range(len(arr)):
    print(arr);
    if i==0:
        break;