# Explain Selection Sort and Python Program for Selection Sort.

1 like 0 dislike
597 views

0 like 0 dislike
by Goeduhub's Expert (9.3k points)

The selection sort algorithm sorts an array by repeatedly finding the minimum element  from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.

1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.

In every iteration of selection sort, the minimum element from the unsorted subarray is picked and moved to the sorted subarray.

Time Complexity: O(n2)

Worst Complexity :  n^2

Average Complexity :  n^2

Auxiliary Space: O(1)

Python program for implementation of Selection Sort:

a=[64, 34, 25, 82, 22, 11, 90]

for i in range(len(a)):

b=i

for j in range(i+1,len(a)):

if a[b]>a[j]:

b=j

a[i],a[b]=a[b],a[i]

print(a)

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.