# Graph & BFS/DFS Confidence: high Last verified: 2026-05-22 Generation: human_only ## TL;DR A graph G=(V,E) models networks. BFS (queue) finds shortest paths in unweighted graphs. DFS (stack/recursion) detects cycles, performs topological sort on DAGs. Both are O(V+E). ## Core Explanation Adjacency list: O(V+E) space, good for sparse graphs. Adjacency matrix: O(V²) space, good for dense. BFS uses queue, level-order traversal — finds shortest path in unweighted graphs. DFS uses stack (or recursion call stack), can be used for maze solving, cycle detection (back edges), strongly connected components. ## Further Reading - [Algorithms (4th Edition)](undefined)