Graph (DFS, BFS)
Graph (DFS, BFS)
Graph
Basics
- Directed Acyclic Graph (DAG): directed graph which does not contain any cycles
Graph Traverse
Depth Fisrt Search (DFS)
Breadth Fisrt Search (BFS)
Topological Sort (TS)
- For a directed graph G = (V, E), a topological order is an assignment o: V → N such that for all (u, v) ∈ E, we have o(u) < o(v).
- Topological order exists if and only if graph is acyclic, i.e. DAG
Algorithm
Implementation using DFS
Strongly Connected Component(SCC) Discovery
Algorithm
- Tarjan’s SCC Discovery
- Using DFS
Minimum Spanning Tree
- A minimum spanning tree connects all the vertices in the graph, ensuring that there is a path between any pair of nodes.
Spanning Tree
- Spanning trees only exist for connected graphs, otherwise a spanning tree exists for each connected component.
- All spanning trees of a graph have the same number of edges.
Visualization
Kruskal’s algorithm
Visualization
Prim’s algorithm
Visualization
Reference
DFS
TS
- https://www.geeksforgeeks.org/dsa/topological-sorting/
- https://www.geeksforgeeks.org/dsa/introduction-to-directed-acyclic-graph/
SCC
Minimal Spanning Tree (MST)
This post is licensed under CC BY 4.0 by the author.
