CSC 213 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

CSC 213

Description:

Problems that can arise with weighted graphs (Sensitive topic for some ... Merlin algorithm takes time O(n m) For Next Lecture. I will not be here on Friday ... – PowerPoint PPT presentation

Number of Views:14
Avg rating:3.0/5.0
Slides: 15
Provided by: wwwcsCa
Category:
Tags: csc | merlin

less

Transcript and Presenter's Notes

Title: CSC 213


1
CSC 213 Large Scale Programming
  • Lecture 34
  • Weighted Graphs Shortest Paths

2
Todays Goal
  • Look at graphs that have weight issues
  • How these weights exist
  • What the weights mean
  • Problems that can arise with weighted graphs
  • (Sensitive topic for some Graphs, be careful!)

3
Weighted Graphs
  • Edges have numerical weight
  • Weights could be distance, cost, travel time, c.
  • In this example, weights are miles between the
    two airports

849
PVD
ORD
1843
142
SFO
802
LGA
1205
1743
337
1387
HNL
2555
1099
1233
LAX
1120
DFW
MIA
4
Shortest Path Problem
  • Find minimum weight path between u v
  • Paths weight is sum of the edge weights
  • Here is shortest path between PVD HNL

849
PVD
ORD
1843
142
SFO
802
LGA
1205
1743
337
1387
HNL
2555
1099
1233
LAX
1120
DFW
MIA
5
Shortest Path Assumptions
  • Subpath of shortest path is also shortest path
  • Shortest path from a vertex to all others is tree
  • Shortest paths from Providence

849
PVD
ORD
1843
142
SFO
802
LGA
1205
1743
337
1387
HNL
2555
1099
1233
LAX
1120
DFW
MIA
6
Dijkstras Algorithm
  • Finds shortest paths from vertex s to all other
    vertices
  • Relies upon several basic assumptions
  • Graph is connected
  • Edge weights are nonnegative (0 or larger)

7
Dijkstras Algorithm
  • Beginning from s, grow cloud of vertices
  • Record distance from s through cloud to each
    vertex v not in the cloud
  • At each step
  • Find vertex, w, with smallest distance not in
    cloud
  • Add w to the cloud
  • See if this creates smaller path to any vertices
    adjacent to w

8
Edge Relaxation
  • Consider Edge e with endvertices u z
  • u added to cloud most recently
  • z is not in the cloud
  • Relaxation of e updates distance to z

d(u) 50
d(z) 60
10
e
z
u
s
d(z) 75

9
Example
0
A
4
8
2
4
2
8
7
1
C
B
D
3
9
?
?
2
5
E
F
0
0
A
A
4
4
8
8
2
2
3
2
8
3
2
7
7
1
7
1
C
B
D
C
B
D
3
9
3
9
5
11
5
8
2
5
2
5
E
F
E
F
10
Example (cont.)
0
A
4
8
2
3
2
7
7
1
C
B
D
3
9
5
8
2
5
E
F
0
A
4
8
2
3
2
7
7
1
C
B
D
3
9
5
8
2
5
E
F
11
Why Dijkstras Algorithm Works
  • Dijkstra was smart. Smarter even than me
  • Algorthm is greedy. Vertices added in order of
    increasing distance
  • Suppose didnt find shortestdistance to F, but
    foundfind shortest distance to D
  • Edge from D to F relaxed when D added to cloud
  • As long as d(F)gtd(D), Fs distance correct

0
A
4
8
2
3
2
7
7
1
C
B
D
3
9
5
8
2
5
E
F
12
Why No Negative-Weight Edges?
  • Suppose Edge has negative weight
  • After adding an incident vertex to cloud, may
    discover smaller distance to opposite vertex
  • But distance set when vertex added to cloud!

0
A
4
8
6
4
5
7
7
1
C
B
D
0
-8
5
9
Cs true distance is 1, but added to cloud with
distance of 5!
2
5
E
F
13
Not All Is Lost
  • Shortest paths algorithms that work with negative
    weights exist
  • Bellman-Ford algorithm takes time O(nm)
  • DAG-based algorithms takes time O(n m)
  • Merlin algorithm takes time O(n m)

14
For Next Lecture
  • I will not be here on Friday
  • Need to go to programming contest/conference
  • Minimum spanning trees lecture now on Monday
  • Use extra time productively
  • Work on programming assignment or lab
  • Also remember portfolios due soon!
Write a Comment
User Comments (0)
About PowerShow.com