Java
Java copied to clipboard
feat(graph): Add Bellman-Ford algorithm with negative cycle detection
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