作者:disappearedgod
时间:2014-6-25
目录
第22章 图的基本算法
22.1 图的表示
22.2 广度优先搜索
最短路径
广度优先树
22.3 深度优先搜索
深度优先搜索的性质
边的分类
22.4 拓扑排序
22.5 强连通分支
正文
第22章 图的基本算法
22.1 图的表示
邻接表与邻接矩阵
In
graph theory
and
computer science
, an
adjacency list
representation of a
graph
is a collection of unordered lists, one for each vertex in the graph. Each list describes the set of neighbors of its vertex.
[fromadjacency list]
In
mathematics
and
computer science
, an
adjacency matrix
is a means of representing which
vertices
(or nodes) of a
graph
are
adjacent
to which other vertices. Another matrix representation for a graph is the
incidence matrix
.
[fromadjacency matrix]
22.2 广度优先搜索(breadth-first search)
在给定图G=(V,E)和一个特定源定点s的情况下,广度优先搜索系统地探索G中的变,以期“发现”可从s达到所有定低昂,并计算s到所有这些可到达定点之间的距离(即最少边数)。
Given a graphG=(V,E) and a distinguished source vertex s, breadth-first search systematically explores the edges of G to “discover” every vertex that is reachable from s.
该算法的副产品是生成一棵根为s、且包括所有s的可达顶点的广度搜索树。
该搜索算法之所以成为广度优先搜索,是因为它始终是将已发现和未发现定点之间的边界,沿其广度方向向外扩展。
BFS(G,s)算法中,pie是u的父节点存储地址,color(白色代表未遍历,灰色代表已经遍历但是兄弟节点未遍历,黑色代表遍历完成)
最短路径
Define the shortest-path distance from s to as the minimum number of edges in any path from vertex s to vertex ; if there is no path from s to , then
. We call a path of length
from s to a shortest path from s to v.
引理22.1
说了一件可达性的事情。
引理22.2
引理22.3推理22.4定理22.5
广度优先树
引理22.6
22.3 深度优先搜索
深度优先搜索的性质
边的分类
深度优先搜索另一个令人感兴趣的性质就是可以通过搜索队输入图G=(V,E)的边进行归类,这种归类可以用来收集有关图的很多重要信息。
根据在图G上进行深度优先搜索所产生的深度优先森林Gπ中的边,可以吧图的边分为四种类型:
1)树边(Tree edge):是深度优先森林Gπ中的边。如果顶点v是在探寻边(u,v)时被首次发现的,那么(u,v)就是一条树边。
2)反向边(back edge):是深度优化树中,连接顶点u到它的某一个祖先顶点v的那些边。
3) 正向边(forward edge):是指深度优先树中,连接顶点u到它的某个后裔v的非树边(u,v)
4)交叉边(cross edge):是其他类型的边,存在于同一棵深度优先树种的两个顶点之间,条件是其中一个顶点不是另一个顶点的祖先。交叉边也可以再不同的深度优先树的顶点之间。