Added Median of Medians Algorithm#9864
Merged
chriso345 merged 5 commits intoTheAlgorithms:masterfrom Oct 8, 2023
Merged
Conversation
for more information, see https://pre-commit.ci
chriso345
requested changes
Oct 5, 2023
searches/median_of_medians.py
Outdated
Comment on lines
10
to
20
|
|
||
| """ | ||
| >>> quick_select([2, 4, 5, 7, 899, 54, 32], 5) | ||
| 32 | ||
| >>> quick_select([2, 4, 5, 7, 899, 54, 32], 1) | ||
| 2 | ||
| >>> quick_select([5, 4, 3, 2], 2) | ||
| 3 | ||
| >>> quick_select([3, 5, 7, 10, 2, 12], 3) | ||
| 5 | ||
| """ |
Collaborator
There was a problem hiding this comment.
Suggested change
| """ | |
| >>> quick_select([2, 4, 5, 7, 899, 54, 32], 5) | |
| 32 | |
| >>> quick_select([2, 4, 5, 7, 899, 54, 32], 1) | |
| 2 | |
| >>> quick_select([5, 4, 3, 2], 2) | |
| 3 | |
| >>> quick_select([3, 5, 7, 10, 2, 12], 3) | |
| 5 | |
| """ |
There is no point in repeating the same tests here.
searches/median_of_medians.py
Outdated
Comment on lines
24
to
38
| """ | ||
| >>> median_of_five([2, 4, 5, 7, 899]) | ||
| 5 | ||
| >>> median_of_five([5, 7, 899, 54, 32]) | ||
| 32 | ||
| >>> median_of_five([5, 4, 3, 2]) | ||
| 3 | ||
| >>> median_of_five([3, 5, 7, 10, 2]) | ||
| 5 | ||
| """ | ||
| """ | ||
| Return the median of the input list | ||
| :param arr: Array to find median of | ||
| :return: median of arr | ||
| """ |
Collaborator
There was a problem hiding this comment.
Can you swap the order of the tests and explanation, and condense into a single docstring
searches/median_of_medians.py
Outdated
Comment on lines
44
to
59
| """ | ||
| >>> median_of_medians([2, 4, 5, 7, 899, 54, 32]) | ||
| 54 | ||
| >>> median_of_medians([5, 7, 899, 54, 32]) | ||
| 32 | ||
| >>> median_of_medians([5, 4, 3, 2]) | ||
| 4 | ||
| >>> median_of_medians([3, 5, 7, 10, 2, 12]) | ||
| 12 | ||
| """ | ||
| """ | ||
| Return a pivot to partition data on by calculating | ||
| Median of medians of input data | ||
| :param arr: The data to be checked (a list) | ||
| :return: median of medians of input array | ||
| """ |
Collaborator
There was a problem hiding this comment.
Can you swap the order of the tests and explanation, and condense into a single docstring
searches/median_of_medians.py
Outdated
Comment on lines
74
to
91
| """ | ||
| >>> quick_select([2, 4, 5, 7, 899, 54, 32], 5) | ||
| 32 | ||
| >>> quick_select([2, 4, 5, 7, 899, 54, 32], 1) | ||
| 2 | ||
| >>> quick_select([5, 4, 3, 2], 2) | ||
| 3 | ||
| >>> quick_select([3, 5, 7, 10, 2, 12], 3) | ||
| 5 | ||
| """ | ||
|
|
||
| """ | ||
| Two way partition the data into smaller and greater lists, | ||
| in relationship to the pivot | ||
| :param arr: The data to be searched (a list) | ||
| :param target: The rank to be searched | ||
| :return: element at rank target | ||
| """ |
Collaborator
There was a problem hiding this comment.
Can you swap the order of the tests and explanation, and condense into a single docstring
chriso345
reviewed
Oct 5, 2023
searches/median_of_medians.py
Outdated
Comment on lines
29
to
30
| >>> median_of_five([5, 4, 3, 2]) | ||
| 3 |
Collaborator
There was a problem hiding this comment.
This test is failing:
>>> median_of_five([5, 4, 3, 2])
Expected:
3
Got:
4
chriso345
approved these changes
Oct 8, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Added an Algorithm: Added Median of medians algorithm to find element at rank k in time complexity O(n)
Checklist: