第07章加权图WeightedGraphs

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

8
8 B
7
0 A
2 2
C
53 9 2E
4
1
3 D
8来自百度文库
7 B
7
0 A
2 2
C
11 F5
53 9 2E
Weighted Graphs
Example:
In a flight route graph, the weight of an edge represents the distance in miles between the endpoint airports
HNL
ORD SFO
LAX
DFW
Weighted Graphs
PVD LGA
Dijkstra’s algorithm computes the distances of all the vertices from a given start vertex s
Assumptions:
the graph is connected
the edges are undirected
Weighted Graphs
8
8 B
7
5 2E
0 A
2 2
C
39
4
1
3 D
8 F5
Weighted Graphs
1
Outline and Reading
Weighted graphs (§7.1) Dijkstra’s algorithm (§7.1.1) The Bellman-Ford algorithm (§7.1.2) Shortest paths in dags (§7.1.3) All-pairs shortest paths (§7.2.1) Shortest Path via Matrix Multiplication (§7.2.2) – No slide on this section- too mathematical for slides! Minimum Spanning Trees (§7.3) The Prim-Jarnik Algorithm (§7.3.2) Kruskal's Algorithm (§7.3.1) Baruvka's Algorithm (§7.3.3)
Weighted Graphs
6
Edge Relaxation
Consider an edge e = (u,z)
such that
u is the vertex most recently
added to the cloud
s
z is not in the cloud
The relaxation of edge e updates distance d(z) as follows:
MIA
3
Shortest Path Problem
Given a weighted graph and two vertices u and v, we want to find a path of minimum total weight between u and v.
Length of a path is the sum of the weights of its edges.
Example:
Tree of shortest paths from Providence
ORD
PVD
SFO
LGA
HNL
LAX
DFW
MIA
Weighted Graphs
5
Dijkstra’s Algorithm
The distance of a vertex v from a vertex s is the length of a shortest path between s and v
the edge weights are nonnegative
We grow a “cloud” of vertices, beginning with s and eventually covering all the vertices
We store with each vertex v a label d(v) representing the distance of v from s in the subgraph consisting of the cloud and its adjacent vertices
Weighted Graphs
2
Weighted Graphs
In a weighted graph, each edge has an associated numerical value, called the weight of the edge
Edge weights may represent, distances, costs, etc.
At each step
We add to the cloud the vertex u outside the cloud with the smallest distance label, d(u)
We update the labels of the vertices adjacent to u
Weighted Graphs
MIA
4
Shortest Path Properties
Property 1:
A subpath of a shortest path is itself a shortest path
Property 2:
There is a tree of shortest paths from a start vertex to all the other vertices
Example:
Shortest path between Providence and Honolulu
Applications
Internet packet routing
Flight reservations
Driving directions
SFO
ORD
PVD
LGA
HNL
LAX
DFW
d(z) min{d(z),d(u) + weight(e)}
s
d(u) = 50
u
e
d(z) = 75
z
d(u) = 50
u
e
d(z) = 60
z
Weighted Graphs
7
Example
8
8 B
7
0 A
2 2
C
4
1
4 D
3 2E
9 F5
8
8 B
7
5 2E
0 A
2 2
C
39
4
1
3 D
8 F5
相关文档
最新文档