On this page
Bellman-Ford
Shortest path with negative edge weights.
Overview
Shortest path with negative edge weights.
Example
Map<Integer, List<Integer>> graph = new HashMap<>();
// Build adjacency list representation
Common Use Cases
- Network routing
- Dependency resolution
- Social graph analysis
Pitfalls to Avoid
- Stack overflow on deep recursion — use iterative DFS
- Not handling disconnected graphs
Related Topics
- BFS vs DFS trade-offs
- Graph vs Tree
Best Practices
- Understand when to use bellman-ford versus simpler alternatives
- Write unit tests covering edge cases and failure paths
- Follow Java conventions and prefer standard library APIs when available
- Profile before optimizing — measure impact in your specific workload