Skip to content
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

Quicksort should shuffle first #27

Open
RyanNaughton opened this issue Oct 20, 2015 · 1 comment
Open

Quicksort should shuffle first #27

RyanNaughton opened this issue Oct 20, 2015 · 1 comment

Comments

@RyanNaughton
Copy link

Quicksort should first randomly shuffle the container. If it doesn't and the array is already sorted, then it will actually be O(n^2), which is the worst case. By shuffling, it results in a probabilistic guarantee of О(n log n).

https://github.com/kanwei/algorithms/blob/master/lib/algorithms/sort.rb#L180

See: http://stackoverflow.com/questions/27645471/how-does-random-shuffling-in-quick-sort-helps-in-increasing-the-efficiency-of-th

@GarrisonJ
Copy link
Contributor

GarrisonJ commented Jan 18, 2024

It looks like this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants