Skip to content

Key Graph Algorithms

Essential graph algorithms for shortest paths, minimum spanning trees, and more. Each major algorithm now has its own detailed page.


Each algorithm is explained in depth on its own page:

AlgorithmPageBest For
DijkstraDijkstra’s Algorithm →Shortest path, non-negative weights
Bellman-FordBellman-Ford Algorithm →Shortest path, handles negative weights
Floyd-WarshallFloyd-Warshall Algorithm →All-pairs shortest path
Topological SortTopological Sort →Ordering DAGs (dependencies, build systems)
Union-Find (DSU)Union-Find (Disjoint Set) →Track connected components, detect cycles
MST (Kruskal & Prim)Minimum Spanning Tree →Kruskal vs Prim for MST
Cycle DetectionCycle Detection →Detect cycles in directed/undirected graphs

flowchart TD
Q1{What problem?}
Q1 --> SP[Shortest Path]
Q1 --> MST[Minimum Spanning Tree]
Q1 --> Other[Structure / Order]
SP --> SP1{Edge weights?}
SP1 -->|Unweighted| BFS["BFS O(V+E)"]
SP1 -->|Non-negative| DIJK["Dijkstra O((V+E) log V)"]
SP1 -->|Negative edges| BF["Bellman-Ford O(V×E)"]
SP1 -->|All pairs| FW["Floyd-Warshall O(V³)"]
MST --> MST1{Graph density?}
MST1 -->|Sparse| KRUS["Kruskal's O(E log E)"]
MST1 -->|Dense| PRIM["Prim's O((V+E) log V)"]
Other --> O1{Detect cycles?}
Other --> O2{Order dependencies?}
Other --> O3{Connected components?}
O1 --> CYCLE["Cycle Detection →"]
O2 --> TOPO["Topological Sort →"]
O3 --> UF["Union-Find (DSU) →"]
style BFS fill:#4f46e5,color:#fff
style DIJK fill:#7c3aed,color:#fff
style BF fill:#4f46e5,color:#fff
style FW fill:#6366f1,color:#fff
style KRUS fill:#059669,color:#fff
style PRIM fill:#059669,color:#fff
style CYCLE fill:#dc2626,color:#fff
style TOPO fill:#dc2626,color:#fff
style UF fill:#dc2626,color:#fff

Apply these algorithms using our Problem-Solving Approach and check the Code Examples for implementations.