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

ENH: turn quicksort into introsort #7863

Merged
merged 2 commits into from
Jul 25, 2016
Merged

Conversation

juliantaylor
Copy link
Contributor

Introsort is regular quicksort but changing to a heapsort when not
enough progress is made. This retains the good quicksort performance
while changing the worst case runtime from O(N^2) to O(N*log(N))

@juliantaylor
Copy link
Contributor Author

another improvement one could do is use a good 3way partitioning scheme for integer sorts, the current simple partition does N swaps on equal elements.

Introsort is regular quicksort but changing to a heapsort when not
enough progress is made. This retains the good quicksort performance
while changing the worst case runtime from O(N^2) to O(N*log(N))
@charris charris changed the title turn quicksort into introsort ENH: turn quicksort into introsort Jul 23, 2016
@charris
Copy link
Member

charris commented Jul 23, 2016

Need to fix the worst case at line 753 in fromnumeric.

@charris
Copy link
Member

charris commented Jul 23, 2016

good 3way partitioning scheme

Java adopted dual-pivot quicksort, which looks to do better. The simplicity of the basic quicksort has a certain attraction.

@juliantaylor
Copy link
Contributor Author

my though in not changing it was older numpy versions still have the worst case, and the worst case maybe includes an older numpy than the user expected ;)
but that is probably a bit overly conservative

@charris
Copy link
Member

charris commented Jul 23, 2016

Maybe put a footnote on it and explanation about versions? I'm not sure on what the markup should be.

@charris charris merged commit 1b16cd8 into numpy:master Jul 25, 2016
@charris
Copy link
Member

charris commented Jul 25, 2016

Thanks Julian.

@pv
Copy link
Member

pv commented Jul 26, 2016

fwiw https://pv.github.io/numpy-bench/#regressions?sort=1&dir=desc (best case seems worse --- also, the sort benchmarks in bench_function_base.py seem a bit silly as they only test this)

@juliantaylor
Copy link
Contributor Author

hm I'm a moron, didn't translate the recursion to iterative properly ...

@juliantaylor juliantaylor deleted the introsort branch July 26, 2016 19:02
@juliantaylor
Copy link
Contributor Author

#7871 should fix it, thanks for checking the benchmarks

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

Successfully merging this pull request may close these issues.

None yet

3 participants