Computer Science - Data Structures - Graph traversal (BFS/DFS) - BFS and DFS Algorithms
4 sections. Section 1 'DFS - Depth First Search': Uses a stack (or recursion). Go as deep as possible, then backtrack. def dfs(graph, start): visited = set(); stack = [start]; while stack: node = stack.pop(); if node not in visited: visited.add(node); for neighbor in graph[node]: stack.append(neighb