Java icon indicating copy to clipboard operation
Java copied to clipboard

feat(graph): Add Bellman-Ford algorithm with negative cycle detection

Open vardhan30016 opened this issue 3 months ago • 1 comments

This PR implements the Bellman-Ford algorithm for finding shortest paths in weighted directed graphs.

Key Features: ✅ Handles negative weight edges (unlike Dijkstra) ✅ Detects negative weight cycles ✅ Comprehensive JavaDoc documentation ✅ Clean API with Result class ✅ Path reconstruction support ✅ Input validation ✅ Early termination optimization

Time Complexity: O(V × E) Space Complexity: O(V)

This implementation fills a gap in the graph algorithms collection and complements existing shortest path implementations.

  • [ ] I have read CONTRIBUTING.md.
  • [ ] This pull request is all my own work -- I have not plagiarized it.
  • [ ] All filenames are in PascalCase.
  • [ ] All functions and variable names follow Java naming conventions.
  • [ ] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • [ ] All new code is formatted with clang-format -i --style=file path/to/your/file.java

vardhan30016 avatar Nov 26 '25 05:11 vardhan30016

Codecov Report

:x: Patch coverage is 89.28571% with 6 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 78.53%. Comparing base (2c4bf3c) to head (e38ff4e).

Files with missing lines Patch % Lines
...main/java/com/thealgorithms/graph/BellmanFord.java 89.28% 4 Missing and 2 partials :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7127      +/-   ##
============================================
+ Coverage     78.51%   78.53%   +0.02%     
- Complexity     6752     6763      +11     
============================================
  Files           759      760       +1     
  Lines         22402    22458      +56     
  Branches       4400     4412      +12     
============================================
+ Hits          17589    17638      +49     
- Misses         4108     4112       +4     
- Partials        705      708       +3     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Nov 26 '25 05:11 codecov-commenter

This pull request has been automatically closed because its workflows or checks failed and it has been inactive for more than 14 days. Please fix the workflows and reopen if you'd like to continue. Merging from main/master alone does not count as activity.

github-actions[bot] avatar Dec 11 '25 03:12 github-actions[bot]