Implementing Depth First Search (DFS) on Graphs with Recursion

Day 88 of my #100DaysOfCode journey 🚀 Today I implemented Depth First Search (DFS) on Graphs using recursion. Unlike BFS, DFS explores as deep as possible along a branch before backtracking. It follows a recursive approach (or stack-based) and is fundamental for many advanced graph problems. Approach: • Start from a source node (0 in this case) • Mark it as visited • Recursively visit all unvisited neighbors Key concepts reinforced: • Graph traversal using DFS • Recursion in graphs • Using a visited set to avoid infinite loops (cycles) Time Complexity: • O(V + E) → where V = vertices, E = edges DFS is widely used in: • Cycle detection • Topological sorting • Connected components • Backtracking problems Now having covered both BFS and DFS, the core graph traversal foundation is in place. Graphs officially unlocked. 🔓 #100DaysOfCode #DSA #Graphs #DFS #Algorithms #Python #CodingJourney #ProblemSolving #TechLearning #SoftwareEngineering

  • text

To view or add a comment, sign in

Explore content categories