跳转到内容

离散数学 · 图论

1 Graphs and Basic Definitions

跳转到:1 Graphs and Basic Definitions
  • Graph: a graph is an ordered pair (V,E)(V, E) where VV is a set of vertices and EE is a set of edges.
  • Every edge has two vertices associated with it, called its endpoints; these two vertices can be different or identical; an edge is said to connect its endpoints.
  • Remark: VV and EE can be infinite, but the course focuses on finite cases.

1.2 Different kinds of graphs

跳转到:1.2 Different kinds of graphs

Graphs are classified along three axes:

  • Directed / Undirected;
  • with or without multiple edges(重边,a.k.a. parallel edges,平行边);
  • with or without loops(自环).

2.1 Adjacency, incidence, neighbourhood, degree (undirected)

跳转到:2.1 Adjacency, incidence, neighbourhood, degree (undirected)
  • Adjacency: if G=(V,E)G=(V,E) is an undirected graph, two vertices u,v∈Vu,v \in V are adjacent (or neighbours) in GG if there is an edge e∈Ee \in E such that the endpoints of ee are u,vu, v.
  • Incidence: if the endpoints of an edge ee are u,vu, v, then ee is incident with u,vu, v.
  • Neighbourhood: N(v)\mathcal{N}(v) is the set of all neighbours of vv; for a vertex set A⊆VA \subseteq V, N(A):=⋃v∈AN(v)\mathcal{N}(A) := \bigcup_{v \in A} \mathcal{N}(v).
  • Degree(度): for an undirected graph G=(V,E)G=(V,E), the degree of a vertex v∈Vv \in V is the number of edges incident with it, where a loop associated with {v,v}\{v,v\} contributes twice to the degree of vv:
deg⁡(v)=∣{e∣v is e’s first endpoint}∣+∣{e∣v is e’s second endpoint}∣=∑v is e’s first endpoint1+∑v is e’s second endpoint1\deg(v) = \big|\{e \mid v \text{ is } e\text{'s first endpoint}\}\big| + \big|\{e \mid v \text{ is } e\text{'s second endpoint}\}\big| = \sum_{v \text{ is } e\text{'s first endpoint}} 1 + \sum_{v \text{ is } e\text{'s second endpoint}} 1

2.2 The Handshaking Theorem(握手定理)

跳转到:2.2 The Handshaking Theorem(握手定理)
  • Handshaking Theorem: if G=(V,E)G=(V,E) is a finite undirected graph, then 2⋅∣E∣=∑v∈Vdeg⁡(v)2 \cdot |E| = \sum_{v \in V} \deg(v).
  • Proof idea (double counting by exchanging summation order — in the first two lines the inner sums run over edges ee, after the exchange the inner sums run over vertices vv):
∑v∈Vdeg⁡(v)=∑v∈V(∑first(e)=v1+∑second(e)=v1)=∑v∑first(e)=v1+∑v∑second(e)=v1=∑e∑first(e)=v1+∑e∑second(e)=v1=∑e1+∑e1=2⋅∣E∣\sum_{v \in V} \deg(v) = \sum_{v \in V}\Big(\sum_{\mathrm{first}(e)=v} 1 + \sum_{\mathrm{second}(e)=v} 1\Big) = \sum_{v}\sum_{\mathrm{first}(e)=v} 1 + \sum_{v}\sum_{\mathrm{second}(e)=v} 1 = \sum_{e}\sum_{\mathrm{first}(e)=v} 1 + \sum_{e}\sum_{\mathrm{second}(e)=v} 1 = \sum_e 1 + \sum_e 1 = 2 \cdot |E|
  • Corollary: an undirected graph has an even number of vertices of odd degree.

2.3 Directed edges, in-degree and out-degree

跳转到:2.3 Directed edges, in-degree and out-degree
  • Directed edges: if G=(V,E)G=(V,E) is a directed graph and e∈Ee \in E is from uu to vv, then: uu is adjacent to vv, and vv is adjacent from uu; uu is the initial vertex of the edge, while vv is the terminal (or end) vertex of the edge.
  • In-degree / out-degree: if G=(V,E)G=(V,E) is a directed graph and v∈Vv \in V:
    • deg⁡−(v):=∣{e∈E∣e is associated with (u′,v′) and v=v′}∣\deg^-(v) := |\{e \in E \mid e \text{ is associated with } (u',v') \text{ and } v = v'\}| (in-degree);
    • deg⁡+(v):=∣{e∈E∣e is associated with (u′,v′) and v=u′}∣\deg^+(v) := |\{e \in E \mid e \text{ is associated with } (u',v') \text{ and } v = u'\}| (out-degree).
  • Degree sum of directed graphs: if G=(V,E)G=(V,E) is a finite directed graph, then ∣E∣=∑v∈Vdeg⁡+(v)=∑v∈Vdeg⁡−(v)|E| = \sum_{v \in V} \deg^+(v) = \sum_{v \in V} \deg^-(v).
  • Path (undirected): for an undirected graph G=(V,E)G=(V,E) and u,v∈Vu,v \in V, a path of length nn (n⩾0n \geqslant 0) from uu to vv in GG is a finite sequence e1,…,ene_1,\ldots,e_n of edges in EE such that there exists a finite sequence of vertices u=x0, x1, …, xn−1, xn=vu = x_0,\ x_1,\ \ldots,\ x_{n-1},\ x_n = v such that the endpoints of each eie_i are xi−1,xix_{i-1}, x_i.
  • The path e1,…,ene_1,\ldots,e_n is simple if it does not contain duplicate edges. The path traverses these edges and passes through the vertices x1, …, xn−1x_1,\ \ldots,\ x_{n-1}.
  • Notation: we write the path e1,…,ene_1,\ldots,e_n as x0,x1,…,xn−1,xnx_0, x_1, \ldots, x_{n-1}, x_n if GG is simple.
  • Circuit (undirected): a path of positive length from uu to uu is a circuit. The circuit is simple if it does not contain duplicate edges.
  • Path (directed): for a directed graph G=(V,E)G=(V,E) and u,v∈Vu,v \in V, a path of length nn (n⩾0n \geqslant 0) from uu to vv is a finite sequence e1,…,ene_1,\ldots,e_n of edges in EE such that there exists a finite sequence of vertices u=x0, x1, …, xn−1, xn=vu = x_0,\ x_1,\ \ldots,\ x_{n-1},\ x_n = v such that each eie_i is from xi−1x_{i-1} to xix_i; simple, traverses and passes through are defined in the same way as in the undirected case.
  • Notation: we write the path e1,…,ene_1,\ldots,e_n as x0,x1,…,xn−1,xnx_0, x_1, \ldots, x_{n-1}, x_n if GG is a simple directed graph.
  • Circuit (directed): a path of positive length from uu to uu is a circuit; it is simple if it does not contain duplicate edges.

4 Connectivity of Undirected Graphs

跳转到:4 Connectivity of Undirected Graphs

4.1 Connected vertices and connected graphs

跳转到:4.1 Connected vertices and connected graphs
  • Connected vertices: in an undirected graph G=(V,E)G=(V,E), two vertices u,v∈Vu, v \in V are connected if there is a path from uu to vv in GG.
  • Basic properties of connectivity in an undirected graph G=(V,E)G=(V,E):
    • for any u∈Vu \in V, uu is connected to itself;
    • for any u,v∈Vu, v \in V, if uu is connected to vv, then vv is connected to uu;
    • for any u,v,w∈Vu, v, w \in V, if uu is connected to vv and vv is connected to ww, then uu is connected to ww.
  • Connected graph(连通图): an undirected graph G=(V,E)G=(V,E) is connected if every pair of vertices in VV is connected; otherwise it is disconnected.

4.2 Subgraphs and connected components

跳转到:4.2 Subgraphs and connected components
  • Subgraph(子图): a subgraph of a graph G=(V,E)G=(V,E) is a graph G′=(V′,E′)G'=(V',E') such that (i) V′⊆VV' \subseteq V and (ii) E′⊆EE' \subseteq E. A subgraph G′G' of GG is proper if G≠G′G \neq G'.
  • A path induces a connected subgraph: if G=(V,E)G=(V,E) is an undirected graph and e1,e2,…,ene_1, e_2, \ldots, e_n is a path in GG from uu to vv that traverses u=x0,x1,…,xn−1,xn=vu = x_0, x_1, \ldots, x_{n-1}, x_n = v, then G′=(V′,E′)G'=(V',E') with V′={x0,x1,…,xn}V' = \{x_0, x_1, \ldots, x_n\} and E′={e1,…,en}E' = \{e_1, \ldots, e_n\} is a connected subgraph of GG.
  • Union of overlapping connected subgraphs: if G=(V,E)G=(V,E) is an undirected graph, G′=(V′,E′)G'=(V',E') and G′′=(V′′,E′′)G''=(V'',E'') are two connected subgraphs of GG, and V′∩V′′≠∅V' \cap V'' \neq \varnothing, then (V′∪V′′, E′∪E′′)(V' \cup V'',\ E' \cup E'') is also a connected subgraph of GG.
  • Induced subgraph(导出子图): for W⊆VW \subseteq V, the subgraph induced by WW consists of all the vertices from WW and all the edges from EE whose endpoints both lie in WW.
  • Connected component(连通块): a connected component of an undirected graph GG is a connected subgraph of GG that is not a proper subgraph of another connected subgraph of GG.
  • Structure of connected components: if GG is a nonempty undirected graph, then GG's connected components are induced subgraphs of VV's subsets of the form {v∈V:v is connected to u}\{v \in V : v \text{ is connected to } u\} for some u∈Vu \in V.
  • Proof structure (two directions, four obligations):
    • 1) Suppose G′=(V′,E′)G'=(V',E') is a connected component of GG: (1a) prove that if u∈V′u \in V', then V′={v∈V:v is connected to u}V' = \{v \in V : v \text{ is connected to } u\}; (1b) prove that E′E' are all edges between two vertices in V′V'.
    • 2) Suppose V′={v∈V:v is connected to u}V' = \{v \in V : v \text{ is connected to } u\} and E′E' are all edges between two vertices in V′V': (2a) prove that G′=(V′,E′)G'=(V',E') is a connected graph; (2b) prove that G′G' is not a proper subgraph of another connected subgraph of GG.

5 Reachability of Directed Graphs

跳转到:5 Reachability of Directed Graphs
  • Strongly-connected directed graph(强连通图): a directed graph G=(V,E)G=(V,E) is strongly connected if for every pair of vertices (u,v)(u,v), there is a path from uu to vv and a path from vv to uu.
  • Strongly-connected component(强连通块): a strongly-connected component of a directed graph GG is a strongly-connected subgraph of GG that is not a proper subgraph of another strongly-connected subgraph of GG.
  • Reachability: a vertex v∈Vv \in V is reachable from u∈Vu \in V if there is at least a path from uu to vv in GG.
  • Mutual reachability: two vertices u,v∈Vu, v \in V are mutually reachable if there are paths both from uu to vv and from vv to uu in GG.
  • Basic properties of mutual reachability in a directed graph GG:
    • for any u∈Vu \in V, uu and itself are mutually reachable;
    • for any u,v∈Vu, v \in V, if uu and vv are mutually reachable, then vv and uu are mutually reachable;
    • for any u,v,w∈Vu, v, w \in V, if uu and vv are mutually reachable, and vv and ww are mutually reachable, then uu and ww are mutually reachable.
  • Structure of strongly-connected components: given a nonempty directed graph GG, its strongly-connected components are induced subgraphs of VV's subsets of the form {v∈V:v is mutually reachable from u}\{v \in V : v \text{ is mutually reachable from } u\} for some u∈Vu \in V.
  • Reachability between components is uniform: if G′=(V′,E′)G'=(V',E') and G′′=(V′′,E′′)G''=(V'',E'') are two strongly-connected components of GG, then for any u1,u2∈V′u_1, u_2 \in V' and v1,v2∈V′′v_1, v_2 \in V'': v1v_1 is reachable from u1u_1 iff v2v_2 is reachable from u2u_2.
  • Circuits live inside one component: if e1,e2,…,ene_1, e_2, \ldots, e_n is a circuit of a directed graph GG passing through x1,x2,…,xnx_1, x_2, \ldots, x_n, then e1,…,ene_1, \ldots, e_n and x1,…,xnx_1, \ldots, x_n belong to the same strongly connected component.

6 Connectivity against Edge Addition / Removal

跳转到:6 Connectivity against Edge Addition / Removal
  • Setting: G=(V,E)G=(V,E) and G′=(V,E∪{e0})G'=(V, E \cup \{e_0\}) are two undirected graphs, where e0∉Ee_0 \notin E is an additional edge connecting uu and vv. Then:
    • For any x,y∈Vx, y \in V: if xx and yy are connected in GG, then xx and yy are still connected in G′G' (adding an edge never destroys connectivity).
    • If uu is connected to vv in GG, then: for any xx and yy, xx and yy are connected in GG iff xx and yy are connected in G′G'.
    • If uu is not connected to vv in GG, then:
      • for any x∈Vx \in V: xx is connected to uu in G′G', iff xx is connected to vv in G′G', iff xx is connected to one of uu and vv in GG;
      • for any xx and yy: if xx and yy are not connected in GG but they are connected in G′G', then xx, yy, uu and vv are all connected in G′G'.

7.1 Definition and basic properties

跳转到:7.1 Definition and basic properties
  • Tree: a tree is a connected (nonempty) undirected graph without simple circuits.
  • Adding an edge: if adding an edge between vertices of a tree, the new graph will have a simple circuit.
  • Removing an edge: if removing an edge from a tree, the new graph will be unconnected.
  • Leaf (in an unrooted tree): a vertex is a leaf in a tree if its degree is 11.
  • If a tree has at least two vertices, then it has at least one leaf; moreover it has at least two leaves.
  • Edge count: a tree with nn vertices has n−1n-1 edges.
  • An undirected graph with no simple circuit is a tree if adding an arbitrary edge between vertices of the graph generates a simple circuit in the new graph.
  • A connected undirected graph is a tree if removing any edge makes the new graph disconnected.

7.2 Equivalent characterizations of trees

跳转到:7.2 Equivalent characterizations of trees

All statements below about a finite undirected graph G=(V,E)G=(V,E) are equivalent:

  • GG is a tree, i.e. GG is connected but contains no simple circuits.
  • GG is connected and ∣E∣=∣V∣−1|E| = |V| - 1.
  • GG contains no simple circuits and ∣E∣=∣V∣−1|E| = |V| - 1.
  • GG is connected, but every edge in EE is a cut edge.
  • GG contains no simple circuits, and adding any edge between vertices of GG generates a simple circuit.
  • There is a unique simple path between any two of GG's vertices.

8 Spanning Trees and Minimum Spanning Trees

跳转到:8 Spanning Trees and Minimum Spanning Trees
  • Spanning tree: a spanning tree of an undirected graph GG is a subgraph of GG that is a tree containing every vertex of GG.
  • Existence: an undirected graph is connected if and only if it has a spanning tree.
  • Proof:
    • (⇐\Leftarrow) If a spanning tree exists, then there is a path in the spanning tree between any two vertices, so the graph is connected.
    • (⇒\Rightarrow) Suppose G0=GG_0 = G is connected. If G0G_0 contains a simple circuit, remove one edge from the simple circuit, generating G1G_1; G1G_1 must still be connected. Repeat this process to construct G2,G3,…G_2, G_3, \ldots; the number of edges keeps decreasing, so there must be a natural number kk such that the number of vertices of GkG_k is one more than its edges — that GkG_k must be a tree.

8.2 Weighted graphs and minimum spanning trees

跳转到:8.2 Weighted graphs and minimum spanning trees
  • Weighted undirected graph: a graph G=(V,E)G = (V,E) with a function that assigns to each edge a (real) number.
  • Minimum spanning tree: for a connected weighted graph GG, a minimum spanning tree of GG is a spanning tree whose sum of all weights in the tree is the minimum among all spanning trees.
  • Construct a minimum spanning tree of a finite connected weighted graph G=(V,E)G=(V,E) according to the following steps:
    1. Choose the initial tree T0=(V0,E0)T_0 = (V_0, E_0) as an arbitrary singleton vertex with no edges.
    2. Construct Tn+1T_{n+1} from TnT_n by adding an edge en+1e_{n+1} with minimum weight among all remaining edges e′e' satisfying that the graph TnT_n added with e′e' is a tree.
    3. Finally T∣V∣−1T_{|V|-1} is a minimum spanning tree.
  • Key step — find en+1e_{n+1} such that:
    • en+1e_{n+1} connects two vertices un+1u_{n+1} and vn+1v_{n+1}, one of which (suppose it is un+1u_{n+1}) is in VnV_n and the other (vn+1v_{n+1}) is in V\VnV \backslash V_n;
    • if there are more than one minimum weighted edges, choose an arbitrary one;
    • Tn+1=(Vn+1,En+1)T_{n+1} = (V_{n+1}, E_{n+1}) where Vn+1=Vn∪{vn+1}V_{n+1} = V_n \cup \{v_{n+1}\} and En+1=En∪{en+1}E_{n+1} = E_n \cup \{e_{n+1}\}.
  • Correctness proof: by induction on nn that there exists a minimum spanning tree T∗T^* such that TnT_n is a subgraph of T∗T^*.
    • When n=0n = 0: choose an arbitrary minimum spanning tree as T∗T^*.
    • When n=∣V∣−1n = |V|-1: if there exists a minimum spanning tree T∗T^* such that T∣V∣−1T_{|V|-1} is a subgraph of T∗T^*, then T∗T^* must be T∣V∣−1T_{|V|-1} itself — done.
    • Induction step: assume there exists a minimum spanning tree T∗T^* such that TnT_n is a subgraph of T∗T^*; show there also exists a minimum spanning tree (maybe different from T∗T^*) such that Tn+1T_{n+1} is a subgraph of it.
      • Choose an arbitrary minimum spanning tree T∗T^* such that TnT_n is a subgraph of T∗T^*. If Tn+1T_{n+1} is a subgraph of T∗T^*, we are done.
      • Otherwise (edge exchange): en+1e_{n+1} is not an edge in T∗T^*. Because T∗T^* is a spanning tree, there is a path in T∗T^* between un+1u_{n+1} and vn+1v_{n+1}. On this path, there must be an edge e∗e^* leaving VnV_n (e∗e^* connects a vertex in VnV_n and a vertex in V\VnV \backslash V_n) — otherwise there would be a path in TnT_n between un+1u_{n+1} and vn+1v_{n+1}, which contradicts the fact that TnT_n is a tree.
      • Because of the choice of en+1e_{n+1}: w(e∗)⩾w(en+1)w(e^*) \geqslant w(e_{n+1}). On the other hand, T∗\{e∗}∪{en+1}T^* \backslash \{e^*\} \cup \{e_{n+1}\} is a tree; because T∗T^* is a minimum spanning tree: w(e∗)⩽w(en+1)w(e^*) \leqslant w(e_{n+1}).
      • Thus, changing e∗e^* to en+1e_{n+1} in T∗T^* gives another minimum spanning tree containing Tn+1T_{n+1} as a subgraph.
  • Construct a minimum spanning tree of a finite connected weighted graph G=(V,E)G=(V,E) according to the following steps:
    1. Choose the initial graph G0=(V,E0)G_0 = (V, E_0) where E0=∅E_0 = \varnothing.
    2. Construct Gn+1G_{n+1} from GnG_n by adding an edge en+1e_{n+1} with minimum weight among all remaining edges e′e' satisfying that the graph GnG_n added with e′e' has no simple circuit. (If more than one edge e′e' has minimum weight, pick an arbitrary one.)
    3. Finally, G∣V∣−1G_{|V|-1} is a minimum spanning tree.
  • Here, Gn+1=(V,En+1)G_{n+1} = (V, E_{n+1}) where En+1=En∪{en+1}E_{n+1} = E_n \cup \{e_{n+1}\}.
  • Correctness proof's main idea: ene_n is "necessary" — assume it connects unu_n and vnv_n; all edges with less weight than ene_n are not enough to connect unu_n and vnv_n, or else there will be a simple circuit in the new graph.
  • Formal proof: by induction on nn that there exists a minimum spanning tree T∗T^* such that GnG_n is a subgraph of T∗T^*.
  • Rooted tree: a rooted tree is a tree with a designated vertex (as the root).
  • Level and height: in a rooted tree G=(V,E)G=(V,E) with root rr: the level of a vertex vv is the length of the unique simple path from rr to vv; the height of the tree is the maximal level of its vertices.
  • Parent and child: the parent of a vertex v≠rv \neq r is the unique vertex uu such that {u,v}∈E\{u,v\} \in E and this edge appears on the unique simple path between rr and vv; vv is called a child of uu.
  • Siblings: vertices u,vu, v are siblings if they have the same parent.
  • Ancestors and descendants: the ancestors of a vertex v≠rv \neq r are the vertices on the simple path from rr to vv, excluding vv but including rr; the descendants of a vertex vv are all vertices that have vv as one of their ancestors.
  • Ancestor transitivity: in a rooted tree GG, if uu is an ancestor of vv and vv is an ancestor of ww, then uu is also an ancestor of ww.
    • Proof sketch: let the simple path from vv to the root be v=xn,xn−1,…,x0=rv = x_n, x_{n-1}, \ldots, x_0 = r and the one from ww to the root be w=ym,ym−1,…,y0=rw = y_m, y_{m-1}, \ldots, y_0 = r. By definition u=xiu = x_i for some 0⩽i<n0 \leqslant i < n and v=yjv = y_j for some 0⩽j<m0 \leqslant j < m. Then v=yj,yj−1,…,y0=rv = y_j, y_{j-1}, \ldots, y_0 = r is also a simple path from vv to the root, so by uniqueness j=nj = n and xn=yn,xn−1=yn−1,…,x0=y0x_n = y_n, x_{n-1} = y_{n-1}, \ldots, x_0 = y_0. Hence u=xi=yiu = x_i = y_i with 0⩽i<n<m0 \leqslant i < n < m, i.e. uu is ww's ancestor.
  • Descendant transitivity: if uu is a descendant of vv and vv is a descendant of ww, then uu is also a descendant of ww.
  • Path extension lemma: in a rooted tree GG, if uu is the parent of vv and u=xn,xn−1,…,x0u = x_n, x_{n-1}, \ldots, x_0 is the simple path from uu to the root, then v,u=xn,xn−1,…,x0v, u = x_n, x_{n-1}, \ldots, x_0 is the simple path from vv to the root.
    • Proof sketch: let v=ym,ym−1,…,y0v = y_m, y_{m-1}, \ldots, y_0 be the simple path from vv to the root; by definition u=ym−1u = y_{m-1}, so ym−1,…,y0y_{m-1}, \ldots, y_0 is the simple path from uu to the root, i.e. n=m−1n = m-1 and xn=yn,…,x0=y0x_n = y_n, \ldots, x_0 = y_0.
  • Ancestors as parent-chains:
    • if uu is vv's ancestor in GG, then there exist w0,w1,…,wkw_0, w_1, \ldots, w_k s.t. w0=uw_0 = u, wk=vw_k = v, and w0w_0 is w1w_1's parent, w1w_1 is w2w_2's parent, etc.;
    • conversely, if w0,w1,…,wkw_0, w_1, \ldots, w_k satisfy w0=uw_0 = u, wk=vw_k = v and w0w_0 is w1w_1's parent, w1w_1 is w2w_2's parent, etc., then uu is vv's ancestor in GG.
  • Paths inside a subtree: in a rooted tree GG, if vv is a descendant of uu, then the unique simple path from vv to uu only passes through uu's descendants and uu.
    • Proof sketch: the simple path from vv to the root is v=xn,…,x0=rv = x_n, \ldots, x_0 = r with u=xmu = x_m for some 0⩽m<n0 \leqslant m < n, so the simple path from vv to uu is v=xn,xn−1,…,xm=uv = x_n, x_{n-1}, \ldots, x_m = u; for any ii with m<i⩽nm < i \leqslant n, xi,xi−1,…,x0=rx_i, x_{i-1}, \ldots, x_0 = r is a subpath and hence the unique simple path from xix_i to the root; since u=xmu = x_m is on this path, xix_i is a descendant of uu.
  • Corollary: in a rooted tree GG, if v1v_1 and v2v_2 are both uu's descendants, the unique simple path from v1v_1 to v2v_2 only passes through uu's descendants and uu.

9.3 Leaves, subtrees, m-ary trees

跳转到:9.3 Leaves, subtrees, m-ary trees
  • Leaf / internal vertex (rooted-tree context): in a rooted tree, a vertex is a leaf if it has no children; otherwise it is an internal vertex.
  • Note the two different leaf notions in this course: in an unrooted tree a leaf is a vertex of degree 11; in a rooted tree a leaf is a vertex with no children.
  • Subtree: the subtree at a vertex vv is the induced subgraph of the vertex set consisting of the vertex vv (as its root) and all the descendants of vv.
  • For any rooted tree G=(V,E)G=(V,E) and v∈Vv \in V, the subtree at vertex vv is a tree.
  • mm-ary trees(mm 叉树): a rooted tree GG is mm-ary if every internal vertex has at most mm children; GG is binary if it is 22-ary.
  • Leaf bound: an mm-ary tree of height hh has at most mhm^h leaves.

10 Depth-First Search(深度优先搜索)

跳转到:10 Depth-First Search(深度优先搜索)

10.1 The DFS procedure (informal)

跳转到:10.1 The DFS procedure (informal)
  • DFS algorithm:
    • Step 1: Fix an arbitrary starting vertex.
    • Step 2: Continuously augment a simple path until no edge is augmentable.
    • Step 3: Trace back to the deepest vertex from which some edge is augmentable and go back to Step 2.
  • Example graph used to illustrate DFS (11 vertices a,b,…,ka, b, \ldots, k; edges read off the figure): {a,c},{b,c},{c,e},{d,e},{d,f},{e,f},{f,g},{f,h},{g,h},{h,i},{h,k},{j,k}\{a,c\}, \{b,c\}, \{c,e\}, \{d,e\}, \{d,f\}, \{e,f\}, \{f,g\}, \{f,h\}, \{g,h\}, \{h,i\}, \{h,k\}, \{j,k\}.

10.2 Describing a DFS process; tree edges and back edges

跳转到:10.2 Describing a DFS process; tree edges and back edges
  • To describe a DFS process: we can say the kk-th move is from vertex uu to vertex vv through edge ee as a forward / backward step; we can also say the kk-th forward move.
  • Tree edge / back edge: in one DFS process, if there is a forward move through ee, then ee is called a tree edge; otherwise ee is called a back edge.

10.3 Formal definition of a DFS process

跳转到:10.3 Formal definition of a DFS process

Given an undirected graph G=(V,E)G=(V,E) and a start point uu, a DFS process (with ss steps) must satisfy the following conditions (assuming that the kk-th step is from vk−1v_{k-1} to vertex vkv_k through edge eke_k):

  • v0=uv_0 = u.
  • If there exists e∈Ee \in E and w∈Vw \in V s.t. w∉{v0,v1,…,vk−1}w \notin \{v_0, v_1, \ldots, v_{k-1}\} and ee connects vk−1v_{k-1} and ww, then the kk-th move must be forward (i.e. go forward whenever an unvisited neighbour exists).
  • If the kk-th move is a forward step, then vk∉{v0,v1,…,vk−1}v_k \notin \{v_0, v_1, \ldots, v_{k-1}\} (forward steps only visit new vertices).
  • If the kk-th move is a backward step and vk−1=viv_{k-1} = v_i, where i⩽k−1i \leqslant k-1 and the ii-th step is forward, then vk=vi−1v_k = v_{i-1} and ek=eie_k = e_i (a backward step retraces the forward edge that first entered the current vertex).
  • DFS yields a spanning tree: all tree edges of a DFS process of a connected undirected graph GG form a spanning tree of GG.
    • Proof scratch: 1) all vertices appear — if vv did not, we could construct a counterexample from a path connecting uu and vv; 2) this subgraph is a tree — by induction over the steps, the subgraph with {v0,v1,…,vk}\{v_0, v_1, \ldots, v_k\} and {e1,e2,…,ek}\{e_1, e_2, \ldots, e_k\} is a tree, proved by case analysis on whether the kk-th step is forward or backward.
    • Usually, we treat this tree as a rooted tree (the starting vertex is the root).
  • A forward step is from a vertex to one of its children (in the DFS tree).
  • Every vertex v≠uv \neq u appears as a forward step's terminal exactly once in a DFS process of a connected undirected graph GG starting from uu.
  • Visited-vertices invariant: for a connected undirected graph G=(V,E)G=(V,E) and a DFS process of GG with ss steps (kk-th step from vk−1v_{k-1} to vkv_k through eke_k) and every k⩽sk \leqslant s, the set of "visited vertices" {v0,v1,…,vk}\{v_0, v_1, \ldots, v_k\} can be divided into three categories:
    • the starting vertex;
    • the vertices which appear as exactly one forward step's termination and as no backward step's starting point in the first kk steps;
    • the vertices which appear as exactly one forward step's termination and as exactly one backward step's starting point in the first kk steps.
  • Moreover, one simple path from v0v_0 to vkv_k satisfies the following properties (proof by induction over kk):
    • it contains only forward edges: en1,en2,…,enle_{n_1}, e_{n_2}, \ldots, e_{n_l}, where 1⩽n1<n2<⋯<nl⩽k1 \leqslant n_1 < n_2 < \cdots < n_l \leqslant k;
    • it passes through vertices vn1−1, vn1=vn2−1, vn2=vn3−1, …, vnl−1=vnl−1, vnl=vkv_{n_1-1},\ v_{n_1} = v_{n_2-1},\ v_{n_2} = v_{n_3-1},\ \ldots,\ v_{n_{l-1}} = v_{n_l-1},\ v_{n_l} = v_k;
    • {v0,vn1,vn2,…,vnl}\{v_0, v_{n_1}, v_{n_2}, \ldots, v_{n_l}\} are exactly all vertices in the first two categories above.
  • Every vertex v≠uv \neq u appears as a backward step's starting point exactly once in a DFS process of a connected undirected graph GG starting from uu.
  • A DFS process of a connected undirected graph with n=∣V∣n=|V| contains n−1n-1 forward steps and n−1n-1 backward steps.
  • Between two visits of uu: if G=(V,E)G=(V,E) is a connected undirected graph and a DFS process of GG contains ss steps with the kk-th step from vk−1v_{k-1} to vkv_k through eke_k, and vi=vj=uv_i = v_j = u with i<ji < j, then vkv_k is uu's descendant or uu itself for every i<k<ji < k < j.
  • Back edge theorem: a back edge is always from a vertex to one of its ancestors, one of its descendants, or itself.
    • Proof: consider an edge from uu to vv. If one of them is the root, the statement is obviously true. Otherwise, consider the backward steps leaving uu and leaving vv; suppose the backward step leaving uu is earlier. Then, right at the time of leaving uu, vv must be visited (or else a forward step should happen). Since a backward step from vv had not yet happened, vv must be uu's ancestor.

10.5 Tarjan's Algorithm for Finding Bridges

跳转到:10.5 Tarjan's Algorithm for Finding Bridges
Tarjan_Bridge(u, e0):
time = time + 1;
dfn(u) = time;
low(u) = time;
for every e ≠ e0 which is incident with u and another vertex v:
if dfn(v) is uninitialized, then
recursively run Tarjan_Bridge(v, e);
low(u) = min(low(u), low(v));
if (low(v) = dfn(v)) then the edge connecting u and v is a bridge;
else
low(u) = min(low(u), dfn(v));
  • The recursion excludes the entering edge e0e_0 itself when scanning the edges incident with uu; dfn(u)\mathrm{dfn}(u) records the visiting time of uu, and low(u)\mathrm{low}(u) is updated by children's low\mathrm{low} values (after recursive calls) and by dfn(v)\mathrm{dfn}(v) of already-visited neighbours; the bridge test is low(v)=dfn(v)\mathrm{low}(v) = \mathrm{dfn}(v).