nullnull**CHAPTER 9 Graphs 9.1 Introduction to Graphs
9.2 Graph Terminology
9.3 Representing Graphs and Graph Isomorphism
9.4 Connectivity
9.5 Euler and Hamilton Paths
9.6 Shortest Path Problems 最短路径问题
9.7 Planar Graphs
9.8 Graph Coloring null**9.6 Shortest Path Problems Introduction Weighted graph 加权图 G = (V,E,W)
We can assign weights to the edges of graphs.
我们可以对图的每一条边赋予一个权值
For example,null**9.6 Shortest Path Problems Introduction Weighted graph G = (V,E,W)
We can assign weights to the edges of graphs. The length of a path in a weighted graph加权图的路径长度
-- the sum of the weights of the edges of this path.
Shortest Path Problems 最短路径问题 null**9.6 Shortest Path Problems A shortest path algorithm 最短路径算法 There are several different algorithms that find the shortest path between two vertices in a weighted graph.
Dijkstra’s Algorithm 迪克斯特拉算法
An algorithm discovered by the Dutch mathematician E. Dijkstra in 1959.
An iterative procedure.一个迭代过程
Proceed by finding the length of the shortest path from a to a first vertex, the length of the shortest path from a to a second vertex, and so on, until the length of the shortest path from a to z. 求出从a到第一个顶点的最短通路的长度,从a到第二个顶点的最短通路的长度,以此类推,直到求出从a到z的最短通路的长度为止null**9.6 Shortest Path Problems The details of Dijkstra’s algorithm迪克斯特拉算法的详细步骤
Dijkstra’s algorithm proceeds by forming a distinguished set of vertices. Let Sk denote this set of vertices after k iterations of labeling procedure.
Step1 Label a with 0 and other with , i.e. L0(a)=0, and L0(v)= and S0=.
Step 2 The set Sk is formed from Sk-1 by adding a vertex u not in Sk-1 with the smallest label. Once u is added to Sk , we update the labels of all vertices not in Sk , so that Lk(v), the label of the vertex v at the kth stage, is the length of the shortest path from a to v that containing vertices only in Sk .
null**9.6 Shortest Path Problems Let v be a vertex not in Sk . To update the label of v, note that Lk(v) is the shortest path from a to v containing only vertices in Sk ,
the shortest path from a to v containing only elements of Sk-1
Or
it is the shortest path from a to u at the (k-1)st stage with the edge (u,v) added.
In other words,
Lk(v)=min{Lk-1(v), Lk-1(u)+w(u,v)}null**9.6 Shortest Path Problems Algorithm 1 Dijkstra’s Algorithm.
Procedure Dijkstra(G: weighted connected simple graph, with
all weights positive)
{G has vertices a = v0, v1 , · · · ,vn =z and weights w(vi ,vj )
where w(vi ,vj )=∞ if {vi ,vj }is not an edge in G}
For i:= 1 to n
L(vi ):= ∞
L(a):=0
S := ø
{the labels are now initialized so that the label of a is zero and
all other labels are ∞,and S is the empty set } null**9.6 Shortest Path Problems While z S
Begin
u :=a vertex not in S with L(u) minimal
S:=S∪ {u}
for all vertices v not in S
if L(u) +w(u,v)
表来代替null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems null**9.6 Shortest Path Problems 【 Theorem 1】 Dijkstra’s algorithm finds the length of a
shortest path between two vertices in a connected simple
undirected weighted graph. 迪克斯特拉算法求出连通简单无向
带权图里两个顶点之间最短通路的长度Proof:
Take as the induction hypothesis the following assertion: At the kth iteration
the label of a vertex v, v0, in S is the length of the shortest path from a to this vertex, and
the label of a vertex not in S is the length of the shortest path from a to this vertex that contains only vertices in S.
k=0
L0(a)=0, L0(v)= , S=null**9.6 Shortest Path Problems (2) Assume that the inductive hypothesis holds for the kth iteration.
Let v be the vertex added to S at the (k+1)st iteration so that v is a vertex not in S at the end of the kth iteration with the smallest label.
(I) holds at the end of the (k+1)st iteration
The vertices in S before the (k+1)st iteration are labeled with the length of the shortest path from a.
v must be labeled with the length of the shortest path to it from a.
If this were not the case, at the end of the kth iteration there would be a path of length less than Lk(v) containing a vertex not in S. null**9.6 Shortest Path Problems Let u be the first vertex not in S in such a path. There is a path with length less than Lk(v) from a to u containing only vertices of S. This contradicts the choice of v.
(II) is true.
Let u be a vertex not in S after k+1 iteration.
A shortest path from a to u containing only elements of S either contains v or it does not.
If it does not contain v, then by the inductive hypothesis its length is Lk(u).
If it does contain v, then it must be made up of a path from a to v of the shortest possible length containing elements of S other than v, followed by the edge from v to u. In this case its length would be Lk(v)+w(v,u). null**9.6 Shortest Path Problems 【 Theorem 2】 Dijkstra’s algorithm uses O(n2 )operations
(additions and comparisons) to find the length of the shortest
path between two vertices in a connected simple undirected
weighted graph. 迪克斯特拉算法使用O( )次运算来求出连
通简单无向带权图里两个顶点之间最短通路的长度Analysis:
Use no more than n-1 iteration
Each iteration,
using no more than n-1 comparisons to determine the vertex not in Sk with the smallest label
no more than 2(n-1) operations are used to update no more than n-1 labelsnull**9.6 Shortest Path Problems The Traveling Salesman Problem The traveling salesman problem
The traveling salesman problem asks for the circuit of minimum total weight in a weighted, complete, undirected graph that visits each vertex exactly once and returns to its starting point.
The equivalent problem:
Find a Hamilton circuit with minimum total weight in the complete graph. null**9.6 Shortest Path Problems Solution of the traveling salesman problem
(1) A straightforward method
Examine all possible Hamilton circuits and select one of minimum total length.
The time complexity:(2) Approximation algorithm
For example,The length of this path: 40
The exact solution ( the length is 37 ):a,c,e,b,d,anull**9.6 Shortest Path Problems Solution of the traveling salesman problem
(1) A straightforward method
Examine all possible Hamilton circuits and select one of minimum total length.
The time complexity:(2) Approximation algorithm
The time complexity:null**9.6 Shortest Path Problems Homework:
P. 601 2, 26