Skip to content

Add a recursive merge sort algorithm that accepts an array as input. #4462

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 14 commits into from
May 30, 2021

Conversation

benfein
Copy link
Contributor

@benfein benfein commented May 28, 2021

Add a recursive merge sort algorithm that accepts an array as input.

Describe your change:

Add a recursive merge sort algorithm that accepts an array as input.

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

Checklist:

  • [x ] 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.
  • [x ] All new Python files are placed inside an existing directory.
  • [x ] All filenames are in all lowercase characters with no spaces or dashes.
  • [x ] All functions and variable names follow Python naming conventions.
  • [ x] All function parameters and return values are annotated with Python type hints.
  • [ x] All functions have doctests that pass the automated testing.
  • [x ] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • [x ] If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

benfein added 2 commits May 28, 2021 19:31
@benfein benfein requested a review from l3str4nge as a code owner May 28, 2021 23:35
@ghost ghost added the require type hints https://docs.python.org/3/library/typing.html label May 28, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

middle = len(arr) // 2
left = arr[:middle]
right = arr[middle:]
leftSize = len(left)
Copy link

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: leftSize

left = arr[:middle]
right = arr[middle:]
leftSize = len(left)
rightSize = len(right)
Copy link

Choose a reason for hiding this comment

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

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: rightSize

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label May 28, 2021
@ghost ghost removed the require type hints https://docs.python.org/3/library/typing.html label May 28, 2021
Copy link
Member

@mrmaxguns mrmaxguns left a comment

Choose a reason for hiding this comment

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

Hello! Thanks for your contribution. This is my review of the code.

The two main things are:

  • If statements are usually written as if EXPRESSION and not if(EXPRESSION)
  • Incrementing a variable and assigning the result to it can be done with +=

If you disagree with any review, please leave a comment. Thanks!

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels May 29, 2021
Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels May 29, 2021
benfein and others added 4 commits May 29, 2021 11:49
Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label May 29, 2021
@mrmaxguns
Copy link
Member

mrmaxguns commented May 29, 2021

Please run Black on your code. Pre-commit failed because Black found issues. Install black with pip install black and run it with black file_name.py.

@ghost ghost added the tests are failing Do not merge until tests pass label May 29, 2021
@ghost ghost added the awaiting reviews This PR is ready to be reviewed label May 29, 2021
@mrmaxguns
Copy link
Member

Flake8 failed because:

 flake8...................................................................Failed
- hook id: flake8
- duration: 8.47s
- exit code: 1

sorts/recursive_mergesort_array.py:16:9: E741 ambiguous variable name 'l'
sorts/recursive_mergesort_array.py:16:9: F841 local variable 'l' is assigned to but never used
sorts/recursive_mergesort_array.py:17:9: F841 local variable 'r' is assigned to but never used

@ghost ghost removed the tests are failing Do not merge until tests pass label May 29, 2021
Copy link
Member

@mrmaxguns mrmaxguns left a comment

Choose a reason for hiding this comment

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

A final review. Please add a docstring to the function briefly describing the mergesort method (and a link to the Wikipedia article for it). Also, please add comments describing various parts of the function (this doesn't have to be excessive, but should help the reader better understand what is happening).

A mergesort function has already been implemented, but I believe this can be merged after review, as the method of implementing the algorithm is different. Thank you for your contribution! 👍

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels May 29, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels May 29, 2021
@mrmaxguns
Copy link
Member

mrmaxguns commented May 30, 2021

I apologize for the wait. Pre-commit failed because of the comments. It wants the comments in the format #  and not ##.

@ghost ghost added the tests are failing Do not merge until tests pass label May 30, 2021
Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
@ghost ghost removed the tests are failing Do not merge until tests pass label May 30, 2021
@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label May 30, 2021
@mrmaxguns mrmaxguns merged commit 650039a into TheAlgorithms:master May 30, 2021
@mrmaxguns
Copy link
Member

Thank you for your contribution 🎆

Kommandat pushed a commit to Kommandat/Python that referenced this pull request May 31, 2021
…heAlgorithms#4462)

This is a different recursive implementation of the merge sort algorithm.

* Recursive Merge Sort That Accepts an Array 

Recursive Merge Sort That Accepts an Array

* Add Wikipedia Link

* Fixes naming conventions

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Adds black format

* Removes unused variables

* Fixes variable names and adds documentation

* Fixes variable names to use snake_case.

* Removes double #.

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
Co-authored-by: Benjamin Fein <benfein78@icloud.com>
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
…heAlgorithms#4462)

This is a different recursive implementation of the merge sort algorithm.

* Recursive Merge Sort That Accepts an Array 

Recursive Merge Sort That Accepts an Array

* Add Wikipedia Link

* Fixes naming conventions

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

* Adds black format

* Removes unused variables

* Fixes variable names and adds documentation

* Fixes variable names to use snake_case.

* Removes double #.

* Update sorts/recursive_mergesort_array.py

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>

Co-authored-by: Maxim R. <49735721+mrmaxguns@users.noreply.github.com>
Co-authored-by: Benjamin Fein <benfein78@icloud.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