Chapter 6 Graph - Shortest Path
BFS (for unweighted shortest path)
void Unweighted( Graph G, Queue Q, int dist[], int path[], Vertex S ){ |
Dijkstra’s Algorithm (for weighted shortest path)
算法非常简单
void Dijkstra(Table T){ |
Not work for negative weight edge
Different Implenentation
- Array
Good if the graph is dense
- Priority Queue
Good if the graph is sparse
SPFA (for graph with negative edge costs)
当遇到负环就无法终止
Topologic Sort (for acylic graphs / DAG)
and no priority queue is needed
AOE Netwoks
Critical Path
All-Pairs Shortest Path
Network Flow Problem
Biconnected Component
See also here
Defination
- Articulation Point
- Biconnected Component
DFS Solution
- Use DFS to obtain a spanning tree of G
- Find the articulation points in G
- The root which has at least 2 children
- The vertex which has at least 1 child and it is impossible to move down and reach its ancestor via back edge
Define
- w is child of u
- (u, v) is a back edge
其中
Low[u]
表示含有 u 的双连通分量第一个被访问的节点的时间戳Num[u]
Therefore, u is an articulation point iff
- u is the root with at least 2 children
- u has at least 1 child v which
Low[v] >= Num[u]
Euler Circuit
一笔画 Introduction see also here
- Eular circuit - 欧拉图
- Eular tour - 欧拉路径
DFS Solution
recursive DFS, until all edge visited