Saturday, March 27, 2021

Selection sort implementation in python

Here is a simple python implementation of selection sort. The asymptotic complexity of selection sort is n^2
#usr/bin/env python
arr = [1,3,6,7,4,6,8,9,1,4,6,7]
for i in range(len(arr)):
for j in range(i,len(arr)):
if arr[j] < arr[i]:
temp = arr[j]
arr[j] = arr[i]
arr[i] = temp
print(arr)
view raw selection.py hosted with ❤ by GitHub