Skip to content

Conversation

@Shubham-Khetan-2005
Copy link
Contributor

Add Bellman-Ford Shortest Path Algorithm in Go

Added an implementation of the Bellman-Ford algorithm for finding the single-source shortest paths in a weighted, directed graph. This algorithm is particularly useful because it correctly handles graphs with negative edge weights and is capable of detecting negative-weight cycles reachable from the source.

Features 🚀

Calculates the shortest distance from a single source node to all other nodes in the graph.

Successfully handles both positive and negative edge weights.

Detects if a negative-weight cycle is reachable from the source node, returning an explicit boolean flag.

If a negative cycle is found, it correctly indicates that shortest paths are undefined by returning nil distance and parent maps.

Includes a comprehensive test suite covering cases with positive weights, negative weights, negative cycles, and disconnected components.

Complexity Analysis 📊

Time Complexity

O(V⋅E), where V is the number of vertices and E is the number of edges. This makes it suitable for most graphs but can be slower than Dijkstra's on graphs that are guaranteed to have no negative-weight edges.

Space Complexity

O(V+E) to store the graph structure (edge list and adjacency list), distances, and parent pointers.

@github-actions
Copy link

github-actions bot commented Oct 8, 2025

🎉 Welcome to Hacktoberfest 2025, @Shubham-Khetan-2005! 🎃

Thank you for your first contribution to our DSA repository! Here's what happens next:

🔍 Automatic Checks

  • Code Validation: Passed
  • 🧪 Compilation Tests: Passed

📋 Next Steps

🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon.

🎁 What You Get

  • 🏆 Hacktoberfest Credit: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
  • 🌟 Hall of Fame: You'll be featured in our contributors list
  • 📚 Learning: Code review feedback from experienced developers

💡 Tips for Success

  • Follow our Contributing Guidelines
  • Add comments explaining your algorithm
  • Include time/space complexity analysis
  • Test your code before submitting

Welcome to the community! 🚀

@github-actions
Copy link

github-actions bot commented Oct 8, 2025

🤖 Automated PR Status

🔍 Code Validation

Passed - File naming and structure look good!

🧪 Compilation Tests

Passed - All code compiles successfully!

📋 Overall Status

🎉 Ready for Review - Your PR has passed all automated checks!
👥 Maintainers have been notified for review.


This comment was generated automatically. Checks will re-run when you push new commits.

@github-actions github-actions bot requested a review from Karanjot786 October 8, 2025 08:10
@Pradeepsingh61 Pradeepsingh61 merged commit 005063c into Pradeepsingh61:main Oct 8, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants