Solutions

Basic

Greedy with HashSet
Graph and BFS
DFS
BFS
DFS
Dijkstra Algorithm
Kruskal Algorithm
Variant of Dijkstra Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Update Ratio in Union of Disjoint Set
Floyd-Warshall Algorithm
Tarjan Algorithm
Held-Karp Algorithm

Supplements

Minimum Spanning Tree

Kruskal Algorithm, O(E log E) time
Prim Algorithm, O((E + V) log V) time

Shortest Path

  • Single Source on Directed Graph with Nonnegative Weights
Dijkstra Algorithm, O((E + V) log V) time
  • Single Source on Weighted Directed Acyclic Graph (DAG)
Topological Sort, Θ(E + V) linear time
  • Single Source on Weighted Directed Graph without Negative Cycles
Bellman-Ford Algorithm, O(VE) time
SPFA, O(VE) time
  • All Pairs on Weighted Directed Graph without Negative Cycles
Floyd-Warshall Algorithm, O(V³) time

Articulation Points/Edges

Tarjan Algorithm, O(E + V) linear time

Traveling Salesman Problem

Held-Karp Algorithm, O(2^n * n²) exponential time

--

--