{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ALG5.2 - Algorithm Algorithms Professor John Reif Breadth...

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

View Full Document Right Arrow Icon
1 Algorithms Professor John Reif ALG 5.2 Breadth-First Search of Graphs: (a) Single Source Shortest Path (b) Graph Matching Main Reading Selections: CLR, Chapter 25 Auxillary Reading Selections: AHU-Design, Sections 5.6-5.10 AHU-Data, Sections 6.3-6.4 Handouts: "Matchings" and "Path-Finding Problems" 2 Breadth First Search Algorithm input undirected graph G = (V,E) with root r e V initialize: L ¨ 0 for each v e V do visit(v) ¨ false LEVEL(0) ¨ {r} ; visit (r) ¨ true while LEVEL(L) π { } do begin LEVEL(L+1) ¨ { } for each v e LEVEL(L) do begin for each {v,u} e E s.t. not visit (u) do add u to LEVEL(L+1) visit (u) ¨ true od end L ¨ L+1 end output LEVEL(0), LEVEL(1), ..., LEVEL(L - 1) O(|V|+|E|) time cost
Image of page 1

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

View Full Document Right Arrow Icon
3 All edges {u,v} e E have level distance £ 1 Example 1 2 3 4 5 6 8 root r LEVEL(0) LEVEL(1) LEVEL(2) 7 1 5 6 8 r 7 3 4 2 LEVEL(0) LEVEL(1) LEVEL(2) Breadth First Search Tree T 4 Single Source Shortest Paths Problem input digraph G=(V,E) with root r e V weighting d:E Æ positive reals Dijkstra's Greedy algorithm initialize: Q ¨ { } for each v e V-{r} do D(v) ¨ D(r) ¨ 0 until no change do choose a vertex u e V-Q with minimum D(u) add u to Q for each (u,v) e E s.t. v e V-Q do D(v) ¨ min(D(v), D(u) + d(u,v)) output " v e V D(v) = weight of min. path from r to v
Image of page 2
5 example 1 2 3 root r 10 30 50 20 40 100 4 5 Q u D(1) D(2) D(3) D(4) D(5) F 1 0 {1} 2 0 10 30 100 {1,2} 3 0 10 30 60 100 {1,2,3} 4 0 10 30 50 100 {1,2,3,4} 5 0 10 30 50 90 6 proof of Dijkstra's Algorithm use induction hypothesis: basis D(r) = 0 for Q={r} { (1 ) " v e V, D(v) i s wei ght of the mi ni mum cos t of path p from r to v, where p vi s i ts onl y verti ces of Q » {v} (2 ) " v e Q, D(v) = mi ni mum cos t path from r to v
Image of page 3

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

View Full Document Right Arrow Icon
7 induction step if D(u) is minimum for all u e V-Q then claim: (1) D(u) is minimum cost of path from r to u in G suppose not: then path p with weight < D(u) and such that p visits a vertex w e V-(Q » {u}). Then D(w) < D(u) , contradiction.
Image of page 4
Image of page 5
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