Skip to content

Conversation

punit1009
Copy link

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.

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.

Translate to Spanish

2 participants