File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Author: OMKAR PATHAK
2
+ # Created On: 31st July 2017
3
+
4
+ # Best O(n^2); Average O(n^2); Worst O(n^2)
5
+
6
+ # selection sort algorithm
7
+ def sort (List ):
8
+ for i in range (len (List ) - 1 ): #For iterating n - 1 times
9
+ minimum = i
10
+ for j in range ( i + 1 , len (List )): # Compare i and i + 1 element
11
+ if (List [j ] < List [minimum ]):
12
+ minimum = j
13
+ if (minimum != i ):
14
+ List [i ], List [minimum ] = List [minimum ], List [i ]
15
+ return List
16
+
17
+ # time complexities
18
+ def bestcase_complexity ():
19
+ return 'O(n ^ 2)'
20
+
21
+ def averagecase_complexity ():
22
+ return 'O(n ^ 2)'
23
+
24
+ def worstcase_complexity ():
25
+ return 'O(n ^ 2)'
26
+
27
+ # easily retrieve the source code of the sort function
28
+ def get_code ():
29
+ import inspect
30
+ return inspect .getsource (sort )
You can’t perform that action at this time.
0 commit comments