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

bpo-21592: Implement non recursive quickselect for statistics.py #6715

Closed
wants to merge 1 commit into from

Conversation

corona10
Copy link
Member

@corona10 corona10 commented May 6, 2018

I read some of not merged PR for this issue.
All of them are recursive versions which can cause a stack overflow.
This version is an iterative version which can avoid this issue.

https://bugs.python.org/issue21592

@corona10 corona10 changed the title bpo-21592: Implement non recursive quickselect for statistics.py [WIP] bpo-21592: Implement non recursive quickselect for statistics.py May 6, 2018
@corona10 corona10 force-pushed the bpo-21592 branch 2 times, most recently from 904fc16 to e50c95d Compare May 6, 2018
@corona10 corona10 changed the title [WIP] bpo-21592: Implement non recursive quickselect for statistics.py bpo-21592: Implement non recursive quickselect for statistics.py May 6, 2018
@corona10 corona10 force-pushed the bpo-21592 branch 2 times, most recently from ede5d46 to 71f350d Compare May 6, 2018
@@ -373,15 +393,20 @@ def median(data):
4.0

"""
data = sorted(data)
data = [d for d in data]
Copy link
Contributor

@scoder scoder May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not calling list(data)?

else:
i = n//2
return (data[i - 1] + data[i])/2
return _quick_select(data, 0, n-1, pos-1)/2 + _quick_select(data, 0, n-1, pos)/2
Copy link
Contributor

@scoder scoder May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be surprised if there wasn't a way to avoid doing the whole expensive operation twice.

@corona10
Copy link
Member Author

corona10 commented May 8, 2018

@scoder Thank you for review, I updated it. 👍

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

4 participants