12 个常见图论算法的时间复杂度。
Dijkstra's Algorithm
for the basic version with an adjacency matrix representation, where is the number of vertices. With a binary heap (priority queue), it improves to , and with a Fibonacci heap, it further improves to , where is the number of edges.
A* Search Algorithm
, but this is highly heuristic-dependent. With a perfect heuristic, it's as efficient as possible. Usually, it behaves similarly to Dijkstra's algorithm in terms of complexity, because it is essentially Dijkstra's algorithm with heuristics.
Bellman-Ford Algorithm
, where is the number of vertices and is the number of edges. This is because it relaxes all edges times.
Floyd-Warshall Algorithm
, where is the number of vertices. This is because it considers all pairs of vertices and iterates through all possible intermediate vertices for each pair.
Breadth-First Search (BFS)
for both adjacency list and adjacency matrix representations of the graph.
Depth-First Search (DFS)
for both adjacency list and adjacency matrix representations of the graph.
Kruskal's Algorithm (for MST)
or , since sorting of edges is required, which takes and the union-find operations take .
Prim's Algorithm (for MST)
Similar to Dijkstra's algorithm, with a basic version, with a binary heap, and with a Fibonacci heap.
Tarjan's Algorithm (for Strongly Connected Components)
, since it is essentially a DFS with additional bookkeeping.
Edmonds-Karp Algorithm (for Maximum Flow)
, because in the worst case, each augmentation of flow can affect all edges, and there can be augmentations per edge.
Ford-Fulkerson Algorithm (for Maximum Flow)
, where is the maximum flow in the graph. This is because the algorithm finds augmenting paths and might do so for each unit of flow.
Johnson's Algorithm (for All-Pairs Shortest Paths):
, which combines the efficiency of Dijkstra's algorithm with a preprocessing step that reweights edges to allow for non-negative weights.