-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create bubble_sort_2.py #1
base: main
Are you sure you want to change the base?
Conversation
another bubble!
Thanks for editing this pull request! |
2 similar comments
Thanks for editing this pull request! |
Thanks for editing this pull request! |
Function sorter2 in file bubble_sort_2.py: Optimization explanation: This function will give you the same result but is much quicker, especially for large arrays. Remember that sort() sorts the list in-place, so no extra space is required. By using Python's built-in function we take advantage of Python's C implementation, further increasing the function's speed. However, it should be noted that Python’s sort() function is a stable sort. This means that when multiple records have the same key, their original order is preserved. Meanwhile, the original function (Bubble Sort) is also stable. Therefore, this change would not affect the overall function's behavior and principle. The code has been tested for correctness. |
⚡️ CodeFlash found optimizations for this PRI created a new dependent PR with the suggested changes, please review:If you approve, it will be merged into this PR (branch |
⚡️ CodeFlash found optimizations for this PRI created a new dependent PR with the suggested changes, please review:If you approve, it will be merged into this PR (branch |
⚡️ CodeFlash found optimizations for this PR
📈 Performance went up by ⏱️ Runtime went down from I created a new dependent PR with the suggested changes. Please review:If you approve, it will be merged into this PR (branch |
⚡️ CodeFlash found optimizations for this PR📄
|
⚡️ CodeFlash found optimizations for this PR📄
|
⚡️ CodeFlash found optimizations for this PR📄
|
⚡️ CodeFlash found optimizations for this PR📄
|
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
⚡️ CodeFlash found optimizations for this PR📄
|
@@ -0,0 +1,3 @@ | |||
def sorter2(arr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def sorter2(arr): | |
def sorter2(arr):\n arr.sort()\n return arr\n | |
No newline at end of file |
⚡️ CodeFlash found optimizations for this PR📄
|
The function you provided, sorter, is already using Python's built-in sort function which has a time complexity of O(n log n), where n is a number of elements in the array. This is the fastest achievable sorting complexity for comparison-based sorts. However, if you want to achieve a marginal speed increase, writing this in-place might help. Here's an alternative version using list comprehension. Although this does not improve the time complexity, it gives a Pythonic touch: ```python def sorter(arr): return sorted(arr) ``` Again, this command returns a new sorted list and does not modify the original list. If you want to sort the list in-place, you only have the original function: Please note that sorting time complexity cannot be improved further than O(n log n) using comparison-based sorting algorithms. To really optimize this function, you would need a guarantee about the content of your data, for example, if your array only contained integers in a particular range, then you could use counting sort or radix sort, which can have a time complexity of O(n).
⚡️ CodeFlash found optimizations for this PR📄
|
The function you provided, sorter, is already using Python's built-in sort function which has a time complexity of O(n log n), where n is a number of elements in the array. This is the fastest achievable sorting complexity for comparison-based sorts. However, if you want to achieve a marginal speed increase, writing this in-place might help. Here's an alternative version using list comprehension. Although this does not improve the time complexity, it gives a Pythonic touch: ```python def sorter(arr): return sorted(arr) ``` Again, this command returns a new sorted list and does not modify the original list. If you want to sort the list in-place, you only have the original function: Please note that sorting time complexity cannot be improved further than O(n log n) using comparison-based sorting algorithms. To really optimize this function, you would need a guarantee about the content of your data, for example, if your array only contained integers in a particular range, then you could use counting sort or radix sort, which can have a time complexity of O(n).
⚡️ CodeFlash found optimizations for this PR📄
|
⚡️ CodeFlash found optimizations for this PR📄
|
The function you provided, sorter, is already using Python's built-in sort function which has a time complexity of O(n log n), where n is a number of elements in the array. This is the fastest achievable sorting complexity for comparison-based sorts. However, if you want to achieve a marginal speed increase, writing this in-place might help. Here's an alternative version using list comprehension. Although this does not improve the time complexity, it gives a Pythonic touch: ```python def sorter(arr): return sorted(arr) ``` Again, this command returns a new sorted list and does not modify the original list. If you want to sort the list in-place, you only have the original function: Please note that sorting time complexity cannot be improved further than O(n log n) using comparison-based sorting algorithms. To really optimize this function, you would need a guarantee about the content of your data, for example, if your array only contained integers in a particular range, then you could use counting sort or radix sort, which can have a time complexity of O(n).
⚡️ CodeFlash found optimizations for this PR📄
|
…21T19.55.22 ⚡️ Speed up `sorter()` by 4211531.56 in PR #1 (`new-sorter`)
This PR is now faster! 🚀 @fake-afik accepted my optimizations from: |
…1-2024-02-21T19.55.22 Revert "⚡️ Speed up `sorter()` by 4211531.56 in PR #1 (`new-sorter`)"
another bubble!aaa fffff