-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
choose pivot from median of three elements for quicksort #171
base: master
Are you sure you want to change the base?
Conversation
Test failures seem to be unrelated? Not sure what's going on there. |
I think it is critical to choose appropriate pivot. If you fix the conflict, it would be really helpful! |
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 147 147
Lines 2590 2595 +5
Branches 432 434 +2
=====================================
+ Hits 2590 2595 +5
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
==========================================
- Coverage 100% 99.58% -0.42%
==========================================
Files 147 128 -19
Lines 2590 2429 -161
Branches 432 413 -19
==========================================
- Hits 2590 2419 -171
- Misses 0 9 +9
- Partials 0 1 +1
Continue to review full report at Codecov.
|
Should be fixed -- I wasn't choosing pivots the right way, and it turned out Kruskal's algorithm was broken... |
@trekhleb Could you have a look please? This makes quicksort better and fixes a bug in Kruskal's algorithm that breaks it in some cases. |
What a nice improvement. @larskotthoff Thanks a lot. The fact that this PR is not merged in is a loss for the repository. |
The repo is mostly dead. |
The method for choosing the pivot as implemented at the moment results in degenerate behaviour when the array is already sorted or reverse sorted. A better way is to choose the median of three elements (first, mid, last) as the pivot. See Robert Sedgewick. Implementing Quicksort Programs. Commun. ACM, 1(10):847–857, October 1978.