Traversal
Visit every vertex with BFS and DFS, then find components, cycles and orderings.
- Breadth-first search Breadth-first search explores a graph in rings of increasing distance using a queue. Watch the frontier expand level by level.
- Depth-first search Depth-first search follows one path as deep as it can, then backtracks. Watch the path dive and retreat alongside the call stack.
- Connected components and flood fill A connected component is a group of vertices that can reach each other. Flood fill colours each component, as in counting islands on a grid.
- Cycle detection in undirected and directed graphs Detect cycles in undirected and directed graphs. In a directed graph, DFS colours nodes white, gray and black, and a gray-to-gray edge…
- Bipartite check by 2-coloring A graph is bipartite when its vertices split into two groups with every edge crossing between them. Two-colour it with BFS and watch for a…
- Topological sort: Kahn's algorithm and DFS finishing order A topological order lists tasks so every dependency comes first. Kahn’s algorithm ticks in-degree counters down; DFS uses finishing order.