File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 1
1
# Author: OMKAR PATHAK
2
+ # Contributors: Mohamed Kiouaz
2
3
# Created On: 31st July 2017
3
4
4
- # Best O(n^2 ); Average O(n^2 ); Worst O(n^2)
5
+ # Best O(n); Average O(n*(n-1)/4 ); Worst O(n^2)
5
6
6
7
# Bubble Sorting algorithm
7
8
def sort (List ):
8
9
for i in range (len (List )):
10
+ stop = True
9
11
for j in range (len (List ) - 1 , i , - 1 ):
10
12
if List [j ] < List [j - 1 ]:
13
+ stop = False
11
14
List [j ], List [j - 1 ] = List [j - 1 ], List [j ]
15
+ if (stop == True ):
16
+ return List
12
17
return List
13
18
14
19
# time complexities
15
20
def time_complexities ():
16
- return '''Best Case: O(n ^ 2), Average Case: O(n ^ 2), Worst Case: O(n ^ 2)'''
21
+ return '''Best case O(n); Average case O(n * (n - 1) / 4); Worst case O(n ^ 2)'''
17
22
18
23
# easily retrieve the source code of the sort function
19
24
def get_code ():
You can’t perform that action at this time.
0 commit comments