File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Python/Sorting-Techniques Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ # program for selection sort
3
+ #selections sort takes O(n^2) time complexity
4
+
5
+
6
+
7
+ #program starts from here
8
+ def selectionSort ( itemsList ):
9
+ n = len ( itemsList )
10
+ for i in range ( n - 1 ):
11
+ minValueIndex = i
12
+
13
+ for j in range ( i + 1 , n ):
14
+ if itemsList [j ] < itemsList [minValueIndex ] :
15
+ minValueIndex = j
16
+
17
+ if minValueIndex != i :
18
+ temp = itemsList [i ]
19
+ itemsList [i ] = itemsList [minValueIndex ]
20
+ itemsList [minValueIndex ] = temp
21
+
22
+ return itemsList
23
+
1
24
# Selection sort in Python
2
25
3
26
# time complexity O(n^2)
@@ -21,3 +44,4 @@ def selectionSort(array, size):
21
44
selectionSort (arr , size )
22
45
print ('The array after sorting in Ascending Order by selection sort is:' )
23
46
print (arr )
47
+
You can’t perform that action at this time.
0 commit comments