← Graph Exploration

Micro-Drill #66 — DFS recursive

Graph Exploration Target: 10s

Recursive DFS is the most natural graph traversal. Watch for stack overflow on deep graphs.

def dfs(node):
    visited.add(node)
    for nb in graph[node]:
        if nb not in visited:
            dfs(nb)

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #65 Micro #67 →