Skip to content

Optimized O(N) -> O(1) for a __contains__ check inside linked_list/has_loop.py#4287

Closed
yoreei wants to merge 6 commits intoTheAlgorithms:masterfrom
yoreei:master
Closed

Optimized O(N) -> O(1) for a __contains__ check inside linked_list/has_loop.py#4287
yoreei wants to merge 6 commits intoTheAlgorithms:masterfrom
yoreei:master

Conversation

@yoreei
Copy link
Copy Markdown

@yoreei yoreei commented Mar 21, 2021

Describe your change:

data_structures/linked_list/has_loop.py: class Node: iter:
Previous implementation used lists for keeping track of visited nodes. The corrected version uses sets. See
https://wiki.python.org/moin/TimeComplexity

  • 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 enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Mar 21, 2021
@algobytewise
Copy link
Copy Markdown
Contributor

I think your comment in line 17 needs one more space before the #-sign if I read the error message correctly.

@yoreei
Copy link
Copy Markdown
Author

yoreei commented Mar 21, 2021

@algobytewise You are right. I also accidentally pushed a separate PR into this one. I'll revert that and make it PEP8 conformant.

@ghost ghost removed the tests are failing Do not merge until tests pass label Mar 21, 2021
@cclauss
Copy link
Copy Markdown
Member

cclauss commented Mar 22, 2021

What would be supercool is to have both approaches in a single file with a timeit (or similar) benchmark that quantifies the performance improvement.

@ghost ghost added the tests are failing Do not merge until tests pass label Mar 22, 2021
@yoreei
Copy link
Copy Markdown
Author

yoreei commented Mar 22, 2021

@cclauss That's a great idea. Thanks for bringing it up.

@stale
Copy link
Copy Markdown

stale bot commented Jun 3, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Jun 3, 2021
@stale
Copy link
Copy Markdown

stale bot commented Jun 16, 2021

Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

@stale stale bot closed this Jun 16, 2021
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 stale Used to mark an issue or pull request stale. tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants