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

Update mergesort.py #2563

Merged
merged 6 commits into from
Oct 15, 2020
Merged

Conversation

akashgkrishnan
Copy link
Contributor

@akashgkrishnan akashgkrishnan commented Oct 1, 2020

  1. Updating the merge sort in python as the previous implementation was modifying the input array
  2. divided the division part and conquer part of the merge sort algorithm as 2 functions namely mergeSort and merge.
  3. function mergeSort divides the function into halves i.e the purpose of the function will be to divide the array
  4. function merge will merge 2 halves into a sorted array
    5)Added random test cases using shuffle as suggested by @dhruvmanila
    6 The time and space complexity of the previous and my version remains the same. i.e (n log(n) time and n log(n) space
  5. changed variables as per the python case as required and suggested by @dhruvmanila
  6. Updated function names as suggested by @dhurvmanila

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

1) Updating the merge sort in python as the previous implementation was modifying the input array
2) divided the division part and conquer part of the merge sort algorithm as 2 functions namely mergeSort and merge.
3) function mergeSort divides the function into halves i.e the purpose of the function will be to divide the array
4) function merge will merge 2 halves into a sorted array
5)Added random test cases using shuffle as suggested by @dhruvmanila
6 The time and space complexity of the previous and my version remains the same. i.e (n log(n) time and n log(n) space
7) changed variables as per the python case as required and suggested by @dhruvmanila
8) Updated function names as suggested by @dhurvmanila
@dhruvmanila
Copy link
Member

Thank you for your contribution!
The way pull request work can be tricky to understand but here's the gist of it:

  • Fork the repo
  • Make a separate branch for whatever you want to contribute
  • Commit the changes in that branch
  • Make the pull request using that branch
  • To make further changes, push more commits to that branch and it will automatically show up here
  • After your changes are merged, delete your branch or the repo (your choice)
  • Repeat

Added in few more test cases 
added type hints for the functions and parameters as suggested by @dhruvmanila
formatted the code using Auto Pep8
@akashgkrishnan
Copy link
Contributor Author

@dhruvmanila kindly review the changes

@dhruvmanila dhruvmanila added the require tests Tests [doctest/unittest/pytest] are required label Oct 3, 2020
update and added new testcases
@akashgkrishnan
Copy link
Contributor Author

@dhruvmanila I have added in more test cases. Please let me know in case further improvements required

Added in doc test in merge function
fixing pre-commit fails
@akashgkrishnan
Copy link
Contributor Author

@dhruvmanila I have made the suggested changes and added in the doc test for the merge function as well.

@dhruvmanila dhruvmanila removed the require tests Tests [doctest/unittest/pytest] are required label Oct 15, 2020
@dhruvmanila dhruvmanila merged commit de2725f into TheAlgorithms:master Oct 15, 2020
@akashgkrishnan akashgkrishnan deleted the patch-4 branch October 15, 2020 09:19
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Update mergesort.py

1) Updating the merge sort in python as the previous implementation was modifying the input array
2) divided the division part and conquer part of the merge sort algorithm as 2 functions namely mergeSort and merge.
3) function mergeSort divides the function into halves i.e the purpose of the function will be to divide the array
4) function merge will merge 2 halves into a sorted array
5)Added random test cases using shuffle as suggested by @dhruvmanila
6 The time and space complexity of the previous and my version remains the same. i.e (n log(n) time and n log(n) space
7) changed variables as per the python case as required and suggested by @dhruvmanila
8) Updated function names as suggested by @dhurvmanila

* Update mergesort.py

Added in few more test cases 
added type hints for the functions and parameters as suggested by @dhruvmanila
formatted the code using Auto Pep8

* Update mergesort.py

update and added new testcases

* Update mergesort.py

Added in doc test in merge function

* Update mergesort.py

fixing pre-commit fails

* Update mergesort.py

Co-authored-by: Dhruv <dhruvmanila@gmail.com>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* Update mergesort.py

1) Updating the merge sort in python as the previous implementation was modifying the input array
2) divided the division part and conquer part of the merge sort algorithm as 2 functions namely mergeSort and merge.
3) function mergeSort divides the function into halves i.e the purpose of the function will be to divide the array
4) function merge will merge 2 halves into a sorted array
5)Added random test cases using shuffle as suggested by @dhruvmanila
6 The time and space complexity of the previous and my version remains the same. i.e (n log(n) time and n log(n) space
7) changed variables as per the python case as required and suggested by @dhruvmanila
8) Updated function names as suggested by @dhurvmanila

* Update mergesort.py

Added in few more test cases 
added type hints for the functions and parameters as suggested by @dhruvmanila
formatted the code using Auto Pep8

* Update mergesort.py

update and added new testcases

* Update mergesort.py

Added in doc test in merge function

* Update mergesort.py

fixing pre-commit fails

* Update mergesort.py

Co-authored-by: Dhruv <dhruvmanila@gmail.com>
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 this pull request may close these issues.

2 participants