跳转至

Chapter 10 - Graphs

约 5597 个字 预计阅读时间 28 分钟

Section 1 Graphs ang Graph Models

A graph G=(V,E) consists of a set V of vertices(nodes) and a set E of edges, where each edge is associated with a pair of vertices.

Types of graphs:

  • Undirected graph: an edge (u,v) is unordered pair of vertices.
    • Simple graph: no loops or multiple edges.
    • Multigraph: may have multiple edges.
    • Pseudograph: may have multiple edges and loops.
  • Directed graph(Digraph): an edge (u,v) is ordered pair of vertices.
    • Simple digraph: no loops or multiple edges.
    • directed multigraph: may have multiple edges, and loops.
  • Mixed graph: a graph that contains both directed and undirected edges.

Undirected graph

  • if (u,v) is an edge, then u and v are adjacent or neighbors, the edge is incident to u and v, and u and v are endpoints of the edge.
  • Loop is an edge that connects a vertex to itself.
  • The neighborhood of a vertex v is the set of vertices adjacent to v. - The degree of a vertex is the number of edges incident to it, with loops counted twice.
    • If deg(v) = 0, then v is an isolated vertex.
    • If deg(v) = 1, then v is a pendant vertex.

Theorem: In any graph, the sum of the degrees of all vertices is equal to twice the number of edges.

Theorem: In any graph, the number of vertices of odd degree is even.

Directed graph

  • if (u,v) is an edge, then u is the initial vertex and is adjacent tov, and v is the terminal vertex and is adjacent from u.
  • Underlying undirected graph of a digraph is the undirected graph obtained by replacing each directed edge by an undirected edge.
  • deg+(v) is the outdegree of v, the number of edges with v as initial vertex.
  • deg(v) is the indegree of v, the number of edges with v as terminal vertex.

Theorem: In any digraph, the sum of the indegrees of all vertices is equal to the sum of the outdegrees of all vertices.

vVdeg+(v)=vVdeg(v)=E \sum_{v \in V} deg^+(v) = \sum_{v \in V} deg^-(v) = |E|

Section 2 Some special graphs

Complete graph (Kn)

A complete graph on n vertices, denoted by Kn, is a simple graph that contains exactly one edge between each pair of distinct vertices.

Cycle graph (Cn)

A cycle graph on n vertices, denoted by Cn, is a simple graph that consists of the vertices v1,v2,...,vn and edges v1v2,v2v3,...,vn1vn,vnv1.

Wheel graph (Wn)

A wheel graph on n vertices, denoted by Wn, is a simple graph that consists of the vertices v1,v2,...,vn and edges v1v2,v2v3,...,vn1vn,vnv1,v1v3,v1v4,...,v1vn.

Cycle graph + one vertex connected to all vertices of the cycle.

n-Cube (Qn)

An n-cube is a graph whose vertices are the n-bit strings and two vertices are adjacent if and only if the corresponding bit strings differ in exactly one bit position.

Q1 is a single vertex, Q2 is a square, Q3 is a cube, Q4 is a hypercube.

Bipartite graph

A graph G=(V,E) is bipartite if V can be partitioned into two sets V1 and V2 such that every edge in E connects a vertex in V1 and a vertex in V2.

The pair (V1,V2) is a bipartition of G.

两色问题:一个图是二分图,当且仅当用两种颜色对图的所有顶点进行着色,使得任意一条边的两个顶点颜色都不相同。

如果每个顶点都和另一个子集的每一个顶点相连,则称为完全二分图

Complete bipartite graph (Km,n)

A complete bipartite graph on m+n vertices, denoted by Km,n, is a bipartite graph that contains exactly one edge between each vertex in V1 and each vertex in V2.

Regular graph

A graph is regular if all vertices have the same degree.

A n-regular graph is a regular graph if all vertices have degree n.

Kn is a (n-1)-regular graph.

New graph from old

Subgraph

G=(V,E),H=(W,F)

  • H is a subgraph of G if WV and FE.
  • H is an proper subgraph of G if GH.
  • H is an spanning subgraph of G if W=V, FE.(相当于从G中删除了一些边)
  • H is an induced subgraph of G if WV, F={uvE|u,vW}.(相当于从G中删除了一些顶点和与这些顶点相关的边)

Some operations

  • Removing edges of a graph: GE=(V,EE).
  • Adding edges to a graph: G+E=(V,EE).
  • Edge contraction: G/e=(V,E), where V=V{u,v}{w} and E contains all edges of E except those incident to u or v, and contains a new edge wx for each edge uy or vy in E(相当于把u,v合并成一个顶点w).
  • Removing vertices of a graph: Gv=(V{v},E), where E contains all edges of E except those incident to v.(相当于删去顶点v及与之相关的边)

  • Graph Union: GH=(VW,EF).

Section 3 Representating graphs and graph isomorphism

Adjacency lists

  • Adjacency list: lists that specify the vertices adjacent to each vertex.

例如:对于无向图

可以用下面的邻接表表示:

vertex adjacent vertices
a b,c,d
b a,d
c a,d
d a,b,c

对于有向图

可以用下面的邻接表表示:

Initial vertex terminal vertices
a c
b a
c
d a,b,c

Adjacency matrices

  • Adjacency matrix: a two-dimensional array A of size n×n, where n=|V|, such that Aij=1 if (vi,vj)E and Aij=0 otherwise.

无向图的邻接矩阵是对称的,有向图的邻接矩阵不一定对称。

例如:对于无向图

可以用下面的邻接矩阵表示:

AG=[0112110110032130]

此时loop不需要乘以2,但是在计算度数时需要乘以2。

每一行加起来的和就是对应顶点的度数减去这个顶点上loop的个数。


对于有向图

可以用下面的邻接矩阵表示:

AG=[0010100000001110]

每一行加起来的和就是对应顶点的出度,每一列加起来的和就是对应顶点的入度。

例如:a13代表的是从顶点1到顶点3的边的个数,即顶点1的出度,在此处是指顶点A的出度。

Incidence matrices

  • Incidence matrix: a two-dimensional array M of size n×m, where n=|V| and m=|E|, such that Mij=1 if vi is incident to ej and Mij=0 otherwise.
  • 其实就是顶点和边的关系矩阵,行代表边,列代表顶点,如果边和顶点相连,则为1,否则为0。

例如:对于无向图

可以用下面的关系矩阵表示:

M=[110010101000000111011100]

Graph isomorphism

  • Graph isomorphism: two graphs G1=(V1,E1) and G2=(V2,E2) are isomorphic if there is a one-to-one correspondence f:V1V2 such that (u,v)E1 if and only if (f(u),f(v))E2.
  • 一般会让你判断两个图是否同构,如果是同构的,就要找到一个一一对应的关系,并记f(u1)=v1,f(u2)=v2,...,f(un)=vn
  • 例子:画出所有四个顶点,三条边的非同构的undirected simple graph。

Section 4 Connectivity

Connectivity

  • Path: a path from vertex v1 to vertex vn is a sequence of vertices v1,v2,...,vn such that (vi,vi+1)E for i=1,2,...,n1.
  • Circuit: a circuit is a path that starts and ends at the same vertex.
  • Simple path/circuit: a simple path/circuit is a path/circuit that does not contain the same edge more than once.
  • Connected: a graph is connected if there is a path from any vertex to any other vertex.
  • Connected component: a connected component of a graph is a maximal connected subgraph.

举个例子:对于下面的图,有四个connected component,分别是{a,b,c,d,e},{f,g,h},{i,j,k},{l}

[Theorem 1] There is a simple path between every pair of distinct vertices of a connected undirected graph.(对于一个连通的无向图,任意两个顶点之间都有一条简单路径。)

cut vertex(割点): a vertex whose removal disconnects the graph.

cut edge/bridge(割边): an edge whose removal disconnects the graph.

举个例子:对于下面的图,点D是一个割点,所有的边都是割边。

nonseparable graph(非分离图): a connected graph that contains no cut vertices.


How to measure the connectivity of a graph?

无向图

  • Vertex cut: a vertex cut of a graph G is a set of vertices whose removal disconnects G.
  • Vertex connectivity: the vertex connectivity of a graph G, denoted by κ(G), is the minimum number of vertices whose removal disconnects G.
  1. The minimum number of vertices whose removal either disconnects G or leaves a graph with only one vertex is called the vertex connectivity of G. (对于一个图G,如果删除最少的顶点,使得图G不连通,或者只剩下一个顶点,则这个最少的顶点数就是图G的顶点连通度。)
  2. κ(G)=0 iff G is disconnected or G=K1
  3. κ(G)=1 if G connected with cut vertices or G=K2
  4. κ(G)=n1 iff G is a complete graph

  5. The larger κ(G) is, the more connected we consider G to be.

k-connected(or k-vertex-connected)(k-连通): a graph G is k-connected if κ(G)k.

  • Edge cut: an edge cut of a graph G is a set of edges whose removal disconnects G.
  • Edge connectivity: the edge connectivity of a graph G, denoted by λ(G), is the minimum number of edges whose removal disconnects G.
  1. The minimum number of edges that can be removed from G to disconnect G
  2. λ(G)=0 iff G is disconnected or G is a graph consisting of a single vertice.
  3. λ(G)=n1 iff G=Kn

κ(G)λ(G)δ(G),其中δ(G)是图G中度数最小的顶点的度数。

有向图

  • strongly connected: a directed graph G is strongly connected if there is a directed path from u to v and a directed path from v to u for every pair of vertices u and v.
  • weakly connected: a directed graph G is weakly connected if if the underlying undirected graph is connected. 每一个强连通图都是弱连通图,但是反过来不一定成立。
  • strongly connected component: a strongly connected component of a directed graph is a maximal strongly connected subgraph. 找强连通分量的方法:先找到一个强连通分量,然后把这个强连通分量中的顶点删除,再找一个强连通分量,直到所有的顶点都被删除。

举个例子:对于下面的图,有三个强连通分量,分别是A;E;the subgraph consisting of vertices

B, C, and D and edges (B,C), (C,D), and (D,B).

用Path判断同构

  • Two graphs are isomorphic only if they have simple circuits of the same length.(两个图同构当且仅当他们有相同长度的简单回路。)
  • Two graphs are isomorphic only if they contain paths that go through vertices so that the corresponding vertices in the two graphs have the same degree.(两个图同构当且仅当他们包含通过顶点的路径,使得两个图中对应的顶点具有相同的度数。)

判断下面的两个图是否同构:

These two graphs are not isomorphic. Because the right graph contains circuits of length 3, while the left graph does not

用矩阵计算路径数

Theorem 2 The number of different paths of length r from vi to vj is equal to the (i,j)th entry of Ar, where A is the adjacency matrix representing the graph consisting of vertices v1,v2,...,vn.

这里计算时不用布尔矩阵,而是用普通的矩阵。

举个例子:对于下面的图,计算从顶点A到顶点D的长度为2的路径数。

AG=[0111100110011110]

AG2=[3112122112212113]

从顶点A到顶点D的长度为2的路径数为2。

Section 5 Euler and Hamilton paths

Euler paths and circuits

  • Euler path: an Euler path in a graph G is a simple path that contains every edge of G.(一笔画)
  • Euler circuit: an Euler circuit in a graph G is a simple circuit that contains every edge of G.(一笔画回到原点)
  • Eulerian graph: a graph that contains an Euler circuit.(可以一笔画回到原点的图)

无向图(undirected graph)

[Theorem 1] A connected graph has an Euler circuit if and only if every vertex has even degree.

[Theorem 2] A connected graph has an Euler path but not an Euler circuit if and only if it has exactly two vertices of odd degree.

Königsberg bridge problem(著名的七桥问题): Is it possible to walk through the city of Königsberg, Prussia, crossing each of its seven bridges exactly once and returning to the starting point? 不成立,因为有四个顶点的度数是奇数。

有向图(directed graph)

[Theorem 3] A connected directed graph has an Euler circuit if and only if every vertex has equal in-degree and out-degree.

[Theorem 4] A connected directed graph has an Euler path but not an Euler circuit if and only if it has exactly two vertices with (out-degree) - (in-degree) = 1 and two vertices with (in-degree) - (out-degree) = 1; all other vertices have equal in-degree and out-degree.

Hamilton paths and circuits

  • Hamilton path: a Hamilton path in a graph G is a simple path that contains every vertex of G.(包括所有顶点的路径)
  • Hamilton circuit: a Hamilton circuit in a graph G is a simple circuit that contains every vertex of G.(包括所有顶点的回路)
  • Hamiltonian graph: a graph that contains a Hamilton circuit.

判断一个图是否是Hamiltonian graph还没有找到有效的方法。

下面是Hamiltonian path的充分条件:

[Theorem 5] If G is a simple graph with n vertices where n3 and deg(v)n2 for every vertex v of G, then G has a Hamilton circuit.

[Theorem 6] If G is a simple graph with n vertices where n3 and deg(u)+deg(v)n1 for every pair of nonadjacent vertices u and v of G, then G has a Hamilton path.

[Theorem 7] If G is a simple graph with n vertices where n3 and deg(u)+deg(v)n for every pair of nonadjacent vertices u and v of G, then G has a Hamilton circuit.

可以用下面的方法判断一个图是否不是Hamiltonian circuit。

  • a graph with a vertex of degree 1 cannot have a Hamilton circuit.
  • If a vertex in the graph has degree 2, then the two edges incident to this vertex must be part of any Hamilton circuit.(如果一个顶点的度数为2,则这个顶点的两条边必须是任何Hamilton回路的一部分。)
  • When a Hamilton circuit is being constructed and this circuit has passed through a vertex, then all remaining edges incident with this vertex, other than the two used in the circuit , can be removed from consideration. (当正在构造一个Hamilton回路时,如果这个回路已经通过了一个顶点,则除了这个回路中使用的两条边之外,所有剩余的与这个顶点相关的边都可以从考虑中删除。)
  • Kn is a Hamiltonian graph for n3.

一个重要的必要条件:如果一个图G是Hamiltonian graph,则对于G的任意一个非空子集SGS的连通分量的个数不超过|S||S|表示集合S中元素的个数。

应用:如果删去顶点后,连通分量的个数比删去的顶点的个数多,则这个图不是Hamiltonian graph。

Section 6 Shortest-path problems

Shortest-path problems

  • Weighted graph(加权图): a weighted graph is a graph in which each edge is assigned a weight.
  • G=(V,E,W),其中w(x,y)表示边(x,y)的权重,如果边(x,y)不存在,则w(x,y)=
  • The length of a path is the sum of the weights of the edges in the path.

Dijkstra's algorithm

  • Dijkstra's algorithm(迪杰斯特拉算法): a method for finding the length of the shortest path from a given vertex to each of the other vertices in a weighted graph.(用于找到从给定顶点到加权图中其他顶点的最短路径的长度的方法。)
  • main idea: 从起点开始,每次找到一个离起点最近的顶点,然后更新这个顶点到其他顶点的距离,直到所有的顶点都被访问过。(贪心算法) [Theorem 1] Dijkstra's algorithm finds the length of the shortest path between two vertices in a connected simple undirected graph with nonnegative edge weights.(适用于简单无向图,边的权重非负)

而且适用于有向图,但是边的权重必须非负。

操作:

  1. 每次从未标记的节点中选择距离出发点最近的节点,标记,收录到最优路径集合中。
  2. 计算与该节点相邻的节点的距离,如果新的距离小于原来的距离,则更新距离。
  3. 重复1、2步骤,直到所有的节点都被标记。

举个例子:对于下面的图,计算从顶点A到其他顶点的最短路径。

先列表:

Vertex S Link L0 L1 L2 L3 L4 L5
a
b
c
d
e
f

初始化,

Vertex S Link L0 L1 L2 L3 L4 L5
a 0
b
c
d
e
f

第一次迭代,以a为起点。

Vertex S Link L0 L1 L2 L3 L4 L5
a 1 0
b a 4
c a 2
d
e
f

第二次迭代,以c为起点。

Vertex S Link L0 L1 L2 L3 L4 L5
a 1 0
b ac 4 3
c 1 a 2
d ac 10
e ac 12
f

第三次迭代,以b为起点。

Vertex S Link L0 L1 L2 L3 L4 L5
a 1 0
b 1 ac 4 3
c 1 a 2
d acb 10 8
e ac 12 12
f

第四次迭代,以d为起点。

Vertex S Link L0 L1 L2 L3 L4 L5
a 1 0
b 1 ac 4 3
c 1 a 2
d 1 acb 10 8
e acbd 12 12 10
f acbd 14

第五次迭代,以e为起点。

Vertex S Link L0 L1 L2 L3 L4 L5
a 1 0
b 1 ac 4 3
c 1 a 2
d 1 acb 10 8
e 1 acbd 12 12 10
f acbde 14 13

第六次迭代,以f为起点。

Vertex S Link L0 L1 L2 L3 L4 L5
a 1 0
b 1 ac 4 3
c 1 a 2
d 1 acb 10 8
e 1 acbd 12 12 10
f 1 acbde 14 13

最后的结果:

a到b的最短路径长度为3,路径为acb。

a到c的最短路径长度为2,路径为ac。

a到d的最短路径长度为8,路径为acbd。

a到e的最短路径长度为10,路径为acbde。

a到f的最短路径长度为13,路径为acbdef。


  • Dijkstra's algorithm复杂度O(n2)
  • 应用模型:The Traveling Salesperson Problem (TSP/旅行商问题)

问题描述:有一个旅行商人要去n个城市,他必须从一个城市出发,经过每个城市一次,最后回到出发的城市。每个城市之间的距离都是已知的,问旅行商人应该如何选择路径,才能保证总的旅行距离最短。

模型:weighted,complete,undirected graph.

等价问题:找到一个Hamilton circuit,使得这个Hamilton circuit的权重最小。

解决方法:穷举法,枚举所有的Hamilton circuit,然后找到权重最小的Hamilton circuit。

Section 7 Planar graphs 平面图

一些概念们:

  • region(区域): a part of the plane completely disconnected off from other parts of the plane by the edges of the graph.(平面上被图的边完全隔离的部分)

Bounded region(有界区域): a region that is bounded by edges of the graph and the boundary of the plane.(被图的边和平面边界隔离的区域)

Unbounded region(无界区域): a region that is not bounded by edges of the graph and the boundary of the plane.(也就是平面上的无穷区域)

The boundary of a region(区域的边界): the edges of the graph that bound the region.(区域被图的边隔离的边)

The degree of a region R Deg(R)(区域的度数): the number of the edges which surround R, suppose R is a region of a connected planar simple graph.(区域被图的边隔离的边的个数)

Adjacent regions(相邻区域): two regions are adjacent if they share a common edge.(两个区域有公共边)

e不是割边的话,必然为两个区域的公共边界。


Example:对于下面的图,有4个区域.

the boundary of region :

  • R1 : a
  • R2 : b,c,e
  • R3 : f,g
  • R0 : a,b,c,d,d,e,f,g

因此,Deg(R1)=1,Deg(R2)=3,Deg(R3)=2,Deg(R0)=8.


Note:

The sum of the degrees of the regions is exactly twice the number of edges in the planar graph, 2e=all region RDeg(R).

  • Planar graph(平面图): a graph is planar if it can be drawn in the plane without any edges crossing.
  • 也就是说,平面图可以被画在平面上,而且不会有边相交。

Note

  • Complete Bipartite Graphs K2,n(n1) are planar.
  • Complete Graphs K1,n are planar.

Planar graphs 的一些必要条件

  • Eular formula(欧拉公式): If G is a connected planar graph with v vertices, e edges, and r regions, then ve+r=2.

Construct a dodecahedron(正十二面体):

用欧拉公式计算出顶点数、边数。正十二面体中r=12

设正十二面体由正n边形组成,所以有rn2条边(每条边被两个正n边形共用)。

假设每个顶点都引出了k条边,所以v=rnk

所以ve+r=2,即rnkrn2+r=2,得到n=536k

所以使得n为正整数的k只有k=5

所以正十二面体包含20个顶点,30条边,12个区域。

  • 欧拉公式对非连通图:ve+r=k+1,其中k是连通分量的个数。
  • [Corollary 1] If G is a connected planar simple graph with v vertices and e edges, where v3, then e3v6.

因为每个区域的度数至少为3,所以2e=all region RDeg(R)3r,所以r23e,代入欧拉公式得到e3v6

  • 对于非连通图:e3v6也成立

因为每个连通分量都满足e3v6,所以e3v6

  • [Corollary 2] If G is a connected planar simple graph with v vertices and e edges, where v3 and G has no circuits of length 3, then e2v4.

因为每个区域的度数至少为4,所以2e=all region RDeg(R)4r,所以r12e,代入欧拉公式得到e2v4

  • Generalization of Corollary 2: If G is a connected planar simple graph with v vertices and e edges, where v3 and G has circuits of length at least k, then e(v2)kk2.

  • [Corollary 3] If G is a connected planar simple graph, then G has a vertex of degree at most 5.

Kuratowski's theorem

一些基本概念:

Elementary subdivision(基本细分): an elementary subdivision of a graph G is a graph obtained from G by subdividing an edge of G.(在边上插入一个顶点)

Homeomorphic(同胚): two graphs are homeomorphic if they can be obtained from the same graph by a sequence of elementary subdivisions and edge contractions.(在边上添加顶点或删去度为2的顶点,使得两个图相同)

[Kuratowski's theorem] A graph is nonplanar if and only if it contains a subgraph that is homeomorphic to K5 or K3,3.

Section 8 Coloring of graphs

Dual graph(对偶图):

  • Each region of the map is represented by a vertex.
  • Edge connect two vertices if the regions represented by these vertices have a common border.
  • Two regions that touch at only one point are not considered adjacent.

Coloring(着色): a coloring of a graph G is an assignment of a color to each vertex of G so that no two adjacent vertices are assigned the same color.(给图的每个顶点赋予一个颜色,使得相邻的顶点颜色不同。)

Chromatic number(色数): the chromatic number of a graph G, denoted by χ(G), is the minimum number of colors needed to color G.

The chromatic numbers of some simple graphs:

  • χ(Kn)=n
  • χ(Cn)=2 if n is even, χ(Cn)=3 if n is odd.
  • χ(Km,n)=2

Note: A simple graph G is bipartite if and only if χ(G)=2.

Construct a coloring of a graph G:

  1. List the vertices in order of decreasing degree.
  2. Color the vertices in this order, using the smallest possible color at each step.
  3. If a vertex cannot be colored with any of the colors already used, then add a new color to the list of available colors and use this color to color the vertex.
  4. Repeat step 3 until all vertices are colored.
  5. The number of colors used is the chromatic number of G.

The Four Color Theorem(四色定理): The chromatic number of any planar graph is at most 4.