DFS Algorithm in Go#545
Conversation
💎 Code Quality Check Results❌ Missing Algorithm DescriptionThese files don't explain what the algorithm does:
Required: Add a description explaining the algorithm, its purpose, and how it works
|
🔍 Duplicate Detection Results
|
|
🎉 Welcome to Hacktoberfest 2025, @Shubham-Khetan-2005! 🎃 Thank you for your first contribution to our DSA repository! Here's what happens next: 🔍 Automatic Checks
📋 Next Steps🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon. 🎁 What You Get
💡 Tips for Success
Welcome to the community! 🚀 |
🤖 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! This comment was generated automatically. Checks will re-run when you push new commits. |
Add Depth-First Search (DFS) Traversal in Go
This implementation uses a recursive approach on a graph represented by an adjacency list. It traverses as far as possible along each branch before backtracking and returns the nodes in preorder (the order they are first visited).
Features 🚀
Represents an undirected graph with integer node IDs using an adjacency list.
Provides a DFS function to initiate the traversal from a specified start node.
Returns the sequence of visited nodes as a slice of integers.
Handles various graph structures, including disconnected components and isolated nodes.
Includes a sample test suite demonstrating correct behavior and edge cases (e.g., missing start node).
Complexity Analysis 📊
Time Complexity
O(V+E), where V is the number of vertices and E is the number of edges, as each vertex and edge is visited once.
Space Complexity
O(V) to store the visited set and for the recursion call stack in the worst-case scenario (for a path graph).