Skip to content

Update quick_select.py #1523

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

Merged
merged 3 commits into from
Oct 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions searches/quick_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def _partition(data, pivot):


def quickSelect(list, k):
"""
>>> quickSelect([2,4,5,7,899,54,32], 5)
54
>>> quickSelect([2,4,5,7,899,54,32], 1)
4
>>> quickSelect([5,4,3,2], 2)
4
>>> quickSelect([3,5,7,10,2,12],3)
7
"""
# k = len(list) // 2 when trying to find the median (index that value would be when list is sorted)

# invalid input
Expand Down