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

Added length instance Variable in singly_linked_list to keep track of length while addition/deletion #5320

Closed
wants to merge 4 commits into from

Conversation

symabbas
Copy link

@symabbas symabbas commented Oct 15, 2021

Describe your change:

Fixes: #5315

  • 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}.

@ghost ghost added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Oct 15, 2021
@symabbas symabbas changed the title Fixes : https://github.com/TheAlgorithms/Python/issues/5315 Fixes : #5315 Oct 15, 2021
@cclauss
Copy link
Member

cclauss commented Oct 15, 2021

Fixes : #5315 is a terrible title for a pull request because if forces the reviewer to manually look up PR #5315. Instead the title should tell what problem the PR fixes and the body of the commit message should contain Fixes : #5315. This does three things...

  1. Tells the reviewer just by (reading the PR title) what this PR does.
  2. Gives the reviewer a link (Singly_Linked_List: extra O(n) time complexity while getting length of the list #5315) to click on to see the issue that this PR fixes.
  3. Allows GitHub to autoclose the issue when the PR is landed.

@ghost ghost added the tests are failing Do not merge until tests pass label Oct 15, 2021
@symabbas symabbas changed the title Fixes : #5315 Added length instance Variable in singly_linked_list to keep track of length while addition/deletion Oct 15, 2021
@cclauss
Copy link
Member

cclauss commented Oct 15, 2021

This is an extra piece of state that must be calculated and that calculation can be a source of bugs. It is much more pythonic to call the len() function than it is to maintain an instance variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Singly_Linked_List: extra O(n) time complexity while getting length of the list
2 participants