Skip to content

Optimize linked list cycle detection using Floyd's algorithm - #1

Merged
suseesuresh2007 merged 1 commit into
masterfrom
Fix-linked-list-loop-detection
Nov 21, 2026
Merged

suseesuresh2007 merged 1 commit into
masterfrom
Fix-linked-list-loop-detection

Conversation

@suseesuresh2007

Copy link
Copy Markdown
Owner

Describe your change

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

Changes made:

  • Optimized linked-list cycle detection using Floyd's Cycle Detection Algorithm.
  • Replaced the list traversal approach with slow and fast pointers.
  • Reduced auxiliary space complexity from O(n) to O(1).
  • Preserved existing functionality.

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.
  • 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 include at least one URL that points to Wikipedia or another similar explanation.
  • Fixes Optimize Node.has_loop to use constant auxiliary space instead of O(N) space TheAlgorithms/Python#15576

Algorithm reference: https://en.wikipedia.org/wiki/Cycle_detection

@suseesuresh2007
suseesuresh2007 merged commit bff0443 into master Nov 21, 2026
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.

Optimize Node.has_loop to use constant auxiliary space instead of O(N) space

1 participant