Repository navigation
Create Bridges.java - #7659
Create Bridges.java#7659rajattiwariind wants to merge 13 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7659 +/- ##
============================================
+ Coverage 82.20% 82.22% +0.02%
- Complexity 8397 8417 +20
============================================
Files 843 844 +1
Lines 26133 26177 +44
Branches 5097 5109 +12
============================================
+ Hits 21482 21524 +42
- Misses 3859 3860 +1
- Partials 792 793 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Move BridgesTest to test source directory
|
Hello maintainers, All 7 CI checks are passing, and Codecov confirms that all modified, coverable lines are covered by tests. Could you please review my pull request when you have a chance? I'm happy to make any changes needed. Thank you for your time. |
DenizAltunkapan
left a comment
There was a problem hiding this comment.
Thank you for the contribution. The bridge-finding logic looks sound, and using edge IDs correctly handles parallel edges. All 19 added tests passed locally; an additional 50,000 seeded random multigraph cases also matched an independent oracle that removes each edge and counts connected components. I ran these checks directly with javac/JUnit rather than a full Maven build.
Before merging, please integrate this work with the existing TarjanBridges implementation and correct the complexity documentation, as detailed in the inline comments. The parallel-edge handling is a useful improvement worth preserving, along with its regression tests.
Non-blocking: the recursive DFS produced a StackOverflowError locally on a 20,000-vertex chain. Recursive DFS is also used by the existing implementation, so I am not requesting an iterative rewrite for this PR, but documenting the recursion-depth limitation would be helpful.
| * | ||
| * <p>Reference: https://en.wikipedia.org/wiki/Bridge_(graph_theory) | ||
| */ | ||
| public final class Bridges { |
There was a problem hiding this comment.
This package already contains TarjanBridges, which implements the same DFS/low-link bridge-finding algorithm: https://github.com/TheAlgorithms/Java/blob/96ed2d7970606b51014afd25212c6c86d2af6255/src/main/java/com/thealgorithms/graph/TarjanBridges.java
Please consolidate this contribution into that implementation rather than maintaining a second copy of the algorithm. In particular, preserve the edge-ID handling and add the parallel-edge regression test to TarjanBridgesTest: for two vertices joined by two parallel edges, the existing implementation incorrectly reports one bridge, while this implementation correctly reports none. If an edge-list entry point is useful, it can be added to TarjanBridges while preserving the existing API and sharing the traversal logic. Please update the PR title/description to explain the resulting improvement.
| * | ||
| * <p>Vertices are numbered from 0 to {@code vertexCount - 1}. | ||
| * | ||
| * <p>Time complexity: O(V + E), where V is the number of vertices |
There was a problem hiding this comment.
The O(V + E) claim does not account for bridges.sort(...) at lines 79–82. With B returned bridges, the implemented method has an upper bound of O(V + E + B log B). Please update the complexity documentation if sorted output is retained, and document the endpoint normalization and lexicographic ordering in the return contract. Alternatively, remove the sorting if ordering is not part of the intended API.
clang-format -i --style=file path/to/your/file.java