lecture11graphs2

# lecture11graphs2 - Weighted Graph Algorithms Weighted...

This preview shows pages 1–15. Sign up to view the full content.

1 Weighted Graph Algorithms. Weighted Shortest Path Problems Dijkstra’s algorithm All Pairs Shortest Path Warshall’s algorithm Minimum spanning trees Prim’s algorithm

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Been there, done that!
3 Shortest-Path in Weighted Graphs Weight w(i, j) associated with each edge (v i , v j ). [sometimes you’ll see c(i,j)] The cost of a path v 1 v 2 ..v n is Find the shortest weighted path from s to every other vertex in G. Single Source Shortest Path - = + 1 1 ) 1 , ( n i i i w

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Shortest-Path Problem Solutions Unweighted Breadth First Search Non-negative Weights Dijkstra’s Algorithm Negative weights with no negative cycles Bellman-Ford Algorithm Negative cycles No solution
5 Dijkstra’s Algorithm Dijkstra (G, v) foreach x V x.dist ; Initially all nodes infinite distance x.p nil ; and no known parent x.known false Q.insert(x) ; Insert into priority queue by dist Q.decreasekey(v, 0) ; Zero distance to first vertex while Q not empty v Q.deletemin() ; Vertex at minimum distance v.known = true foreach x such that (v,x) E and !x.known if v.dist + w(v,x) < x.dist then Q.decreasekey(x, v.dist + w(v,x) ) x.p v

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Example v 3 2 v 6 v 5 v 4 v 2 v 7 4 10 1 3 2 5 8 1 4 2 6 v d v v 1 0 v 2 v 3 v 4 v 5 v 6 v 7 Initialization Priority Queue v 0
7 Example v d v v 4 1 v 2 2 v 3 v 5 v 6 v 7 Priority Queue Process v 1 v 3 2 v 6 v 5 v v v v 7 4 10 1 3 2 5 8 1 4 2 6 0 2 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Example v d v v 2 2 v 3 3 v 5 3 v 7 5 v 6 9 Priority Queue Process v 4 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 0 2 1 3 3 5 9
9 Example v d v v 3 3 v 5 3 v 7 5 v 6 9 Priority Queue Process v 2 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 0 2 1 3 3 5 9 V 4 already known V 5 not shorter

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
10 Example v d v v 5 3 v 7 5 v 6 8 Priority Queue Process v 3 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 0 2 1 3 3 5 8 V 1 already known V 6 shorter
11 Example v d v v 7 5 v 6 8 Priority Queue Process v 5 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 0 2 1 3 3 5 8 V 7 not shorter

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
12 Example v d v v 6 6 Priority Queue Process v 7 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 0 2 1 3 3 5 6 V 6 shorter
13 Example v d v Priority Queue Process v 6 v 2 v v v v v v 4 10 1 3 2 5 8 1 4 2 6 0 2 1 3 3 5 6 We be done!

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
14 Dijkstra’s Algorithm Dijkstra (G, v) foreach x V x.dist ; Initially all nodes infinite distance x.p nil ; and no known parent x.known false Q.insert(x) ; Insert into priority queue by dist Q.decreasekey(v, 0)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern