Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(graph): return ordered cycle path and add early exit in detectUndirectedCycle #2080

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

Open
punit1009 wants to merge 5 commits into trekhleb:master
base: master
Choose a base branch
Loading
from punit1009:fix/detect-undirected-cycle-#2057

Conversation

@punit1009
Copy link

@punit1009 punit1009 commented Oct 5, 2025

Summary

This fixes issue #2057 .

The detectUndirectedCycle function previously returned a vertex-to-parent mapping which was unintuitive and difficult to consume. This PR changes the function to return an ordered array of vertices forming the cycle (e.g. [A, B, C, A]), with the first and last elements equal to clearly indicate the cycle closure.

Changes

  • Return ordered cycle path array instead of object map.
  • Add early exit (stop traversal once a cycle is found).
  • Ensure function iterates all graph components (handles disconnected graphs).
  • Add unit tests to verify behavior and maintain 100% coverage.

Checklist

  • Code matches repository style
  • npm run lint passes (or auto-fixed)
  • npm test passes
  • 100% test coverage for modified files

Fixes #123

Copy link

@asanpardazzagros-debug asanpardazzagros-debug left a comment

Choose a reason for hiding this comment

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

Copy link
Author

Could you please confirm whether this workflow will be approved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@asanpardazzagros-debug asanpardazzagros-debug asanpardazzagros-debug left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Translate to Spanish

AltStyle によって変換されたページ (->オリジナル) /