Trail: a walk that does not repeat any edges.
Closed Trail(Circuit): a trail that begins and ends at the same vertex.
Eulerian Circuit: a circuit that includes every edge of the graph.
Eulerian Trail: a trail that includes every edge of the graph.
在无向图中,图 $G$ 有欧拉回路当且仅当每个点的度数为偶数。
在有向图中,图 $G$ 有欧拉回路当且仅当每个点的入度和出度相同。
在无向图中,图 $G$ 有欧拉路径(非欧拉回路)当且仅当只有两个点的度数为奇数,其余都是偶数。
在有向图中,图 $G$ 有欧拉路径(非欧拉回路)当且仅当只有两个点的入度和出度不同,且其中一个点的“入度 $-$ 出度=1”,另一个点的“出度 $-$ 入度=1”。
输出欧拉回路和欧拉路径的常用算法是 Hierholzer's Algorithm 和 Fleury's Algorithm,复杂度分别为 $O(E)$ 和 $O(E^2)$。
Hierholzer's Algorithm的正确性:因为一个具有欧拉回路的图G能够拆分成多个边不相交的环,因此这个算法正确。
1 Find a circuit called $R_1$ 2 mark all edges of $R_1$ 3 i=1; 4 while(true) 5 { 6 if $R_1$ contains all edges of G, then return; 7 else 8 { 9 let $v_i$ be a vertex on $R_i$ that is incident with unmarked edge; 10 build a circuit $Q_i$ from $v_i$; 11 mark all edges of $Q_i$; 12 $R_{i+1} = R_i \cup Q_i$; 13 i++; 14 } 15 }