lecture11graphs2 - Weighted Graph Algorithms Weighted...

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

View Full Document Right Arrow Icon
1 Weighted Graph Algorithms. Weighted Shortest Path Problems Dijkstra’s algorithm All Pairs Shortest Path Warshall’s algorithm Minimum spanning trees Prim’s algorithm
Image of page 1

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

View Full Document Right Arrow Icon
2 Been there, done that!
Image of page 2
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
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 4
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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 6
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
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 8
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
Image of page 9

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

View Full Document Right Arrow Icon
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
Image of page 10
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
Image of page 11

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

View Full Document Right Arrow Icon
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
Image of page 12
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!
Image of page 13

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

View Full Document Right Arrow Icon
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)
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern