Skip to content

Commit

Permalink
⚡️ Speed up function sorter by 764,385%
Browse files Browse the repository at this point in the history
Certainly! The original program uses a bubble sort algorithm, which is inefficient for large datasets. To improve the runtime, we can use Python's built-in `sort` method, which implements Timsort, an adaptive sorting algorithm that provides better performance. Here's the rewritten program.



This change will significantly reduce the running time of the sorting operation, especially for larger arrays.
  • Loading branch information
codeflash-ai[bot] authored Nov 23, 2024
1 parent 97f70aa commit 67633e7
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions bubble_sort.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
def sorter(arr):
for i in range(len(arr)):
for j in range(len(arr) - 1):
if arr[j] > arr[j + 1]:
temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
arr.sort()
return arr

0 comments on commit 67633e7

Please sign in to comment.