Skip to content

Commit cdbc88f

Browse files
⚡️ Speed up function sorter by 132,409% in PR #63 (verify-bubble-sort)
Sure, the given code is an implementation of Bubble Sort, which is inefficient. We can optimize it by using Python's built-in sorting function which is highly optimized. Here is the optimized version. This optimized version utilizes Timsort, which has a time complexity of O(n log n) in the worst case, making the sorting process significantly faster than the original Bubble Sort implementation.
1 parent a4f3c56 commit cdbc88f

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

codeflash/bubble_sort.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
def sorter(arr):
2-
for i in range(len(arr)):
3-
for j in range(len(arr) - 1):
4-
if arr[j] > arr[j + 1]:
5-
temp = arr[j]
6-
arr[j] = arr[j + 1]
7-
arr[j + 1] = temp
8-
return arr
2+
# Using Python's built-in sort function which is implemented using Timsort
3+
arr.sort()
4+
return arr

0 commit comments

Comments
 (0)