Single Source Shortest Paths (with Positive Weights)

Similar documents
Lecture 20: Minimum Spanning Trees (CLRS 23)

Weighted Graphs. Weighted graphs may be either directed or undirected.

Depth First Search. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

Spanning Trees. BFS, DFS spanning tree Minimum spanning tree. March 28, 2018 Cinda Heeren / Geoffrey Tien 1

CMPS 2200 Fall Graphs. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

(Minimum) Spanning Trees

5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees

4.1 Interval Scheduling. Chapter 4. Greedy Algorithms. Interval Scheduling: Greedy Algorithms. Interval Scheduling. Interval scheduling.

The University of Sydney MATH 2009

Divided. diamonds. Mimic the look of facets in a bracelet that s deceptively deep RIGHT-ANGLE WEAVE. designed by Peggy Brinkman Matteliano

Minimum Spanning Trees (CLRS 23)

COMP 250. Lecture 29. graph traversal. Nov. 15/16, 2017

Improving Union. Implementation. Union-by-size Code. Union-by-Size Find Analysis. Path Compression! Improving Find find(e)

Strongly connected components. Finding strongly-connected components

Having a glimpse of some of the possibilities for solutions of linear systems, we move to methods of finding these solutions. The basic idea we shall

Graph Search (6A) Young Won Lim 5/18/18

CMSC 451: Lecture 4 Bridges and 2-Edge Connectivity Thursday, Sep 7, 2017

Minimum Spanning Trees

CSE 332. Data Structures and Parallelism

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

Lecture II: Minimium Spanning Tree Algorithms

2 Trees and Their Applications

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

Minimum Spanning Trees (CLRS 23)

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

COMP108 Algorithmic Foundations

CS 103 BFS Alorithm. Mark Redekopp

The R-Tree. Yufei Tao. ITEE University of Queensland. INFS4205/7205, Uni of Queensland

Minimum Spanning Trees

Graphs Depth First Search

23 Minimum Spanning Trees

Graph Search Algorithms

Preview. Graph. Graph. Graph. Graph Representation. Graph Representation 12/3/2018. Graph Graph Representation Graph Search Algorithms

MAT3707. Tutorial letter 201/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/201/1/2017

In which direction do compass needles always align? Why?

Closed Monochromatic Bishops Tours

CSE 332. Graphs 1: What is a Graph? DFS and BFS. Data Abstractions. CSE 332: Data Abstractions. A Graph is a Thingy... 2

Platform Controls. 1-1 Joystick Controllers. Boom Up/Down Controller Adjustments

Minimum Spanning Trees

Theorem 1. An undirected graph is a tree if and only if there is a unique simple path between any two of its vertices.

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Graphs Breadth First Search

d e c b a d c b a d e c b a a c a d c c e b

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Planar convex hulls (I)

Maximum Matching Width: new characterizations and a fast algorithm for dominating set

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

Spanning Tree. Preview. Minimum Spanning Tree. Minimum Spanning Tree. Minimum Spanning Tree. Minimum Spanning Tree 10/17/2017.

Applications of trees

17 Basic Graph Properties

Functions and Graphs 1. (a) (b) (c) (f) (e) (d) 2. (a) (b) (c) (d)

Planar Upward Drawings

Face Detection and Recognition. Linear Algebra and Face Recognition. Face Recognition. Face Recognition. Dimension reduction

Garnir Polynomial and their Properties

23 Minimum Spanning Trees

a g f 8 e 11 Also: Minimum degree, maximum degree, vertex of degree d 1 adjacent to vertex of degree d 2,...

Graph Search Algorithms CSE

Tangram Fractions Overview: Students will analyze standard and nonstandard

Exam 2 Solutions. Jonathan Turner 4/2/2012. CS 542 Advanced Data Structures and Algorithms

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

FINITE ELEMENT ANALYSIS OF

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

The Constrained Longest Common Subsequence Problem. Rotem.R and Rotem.H

An Introduction to Clique Minimal Separator Decomposition

On Hamiltonian Tetrahedralizations Of Convex Polyhedra

Last time: introduced our first computational model the DFA.

1 Introduction to Modulo 7 Arithmetic

dy 1. If fx ( ) is continuous at x = 3, then 13. If y x ) for x 0, then f (g(x)) = g (f (x)) when x = a. ½ b. ½ c. 1 b. 4x a. 3 b. 3 c.

A general N-dimensional vector consists of N values. They can be arranged as a column or a row and can be real or complex.

16.unified Introduction to Computers and Programming. SOLUTIONS to Examination 4/30/04 9:05am - 10:00am

No-bend Orthogonal Drawings of Series-Parallel Graphs

learning objectives learn what graphs are in mathematical terms learn how to represent graphs in computers learn about typical graph algorithms

18 Basic Graph Properties

Shortest Paths in Graphs. Paths in graphs. Shortest paths CS 445. Alon Efrat Slides courtesy of Erik Demaine and Carola Wenk

MATERIAL SEE BOM ANGLES = 2 FINISH N/A

Grade 7/8 Math Circles March 4/5, Graph Theory I- Solutions

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

Chapter Interval Scheduling. Greedy Algorithms. What is a Greedy Algorithm? Interval Scheduling

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

ERDOS-SMARANDACHE NUMBERS. Sabin Tabirca* Tatiana Tabirca**

0.1. Exercise 1: the distances between four points in a graph

Linear Algebra Existence of the determinant. Expansion according to a row.

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

CS 461, Lecture 17. Today s Outline. Example Run

(2) If we multiplied a row of B by λ, then the value is also multiplied by λ(here lambda could be 0). namely

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V


Ch 1.2: Solutions of Some Differential Equations

Formal Concept Analysis

Graph Algorithms and Combinatorial Optimization Presenters: Benjamin Ferrell and K. Alex Mills May 7th, 2014

(4, 2)-choosability of planar graphs with forbidden structures

Fractions. Mathletics Instant Workbooks. Simplify. Copyright

SAMPLE CSc 340 EXAM QUESTIONS WITH SOLUTIONS: part 2

MINI POST SERIES BALUSTRADE SYSTEM INSTALLATION GUIDE PRODUCT CODE: MPS-RP

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

Transcription:

Snl Sour Sortst Pts (wt Postv Wts) Yuf To ITEE Unvrsty of Qunslnd

In ts ltur, w wll rvst t snl sour sortst pt (SSSP) problm. Rll tt w v lrdy lrnd tt t BFS lortm solvs t problm ffntly wn ll t ds v t sm wt. Tody w wll s ow to solv t problm n t mor nrl stuton wr t ds n v rbtrry postv wts. W wll dsuss two vrnts of t problm, dpndn on wtr t nput rp s DAG or not. T formr s lrly spl s of t lttr, nd s rsult, dmts fstr lortm.

Wtd Grps Lt G = (V, E) b drtd rp. Lt w b funton tt mps d n E to postv ntr vlu. Spflly, for E, w() s postv ntr vlu, w w ll t wt of. A drtd wtd rp s dfnd s t pr (G, w).

Exmpl 6 5 0 3 T ntr on d ndts ts wt. For xmpl, w(d, ) =, w(, f ) =, nd w(, ) = 0.

Sortst Pt Consdr drtd wtd rp dfnd by drtd rp G = (V, E) nd funton w. Consdr pt n G: (v, v ), (v, v 3 ),..., (v l, v l+ ), for som ntr l. W dfn t lnt of t pt s l w(v, v + ). = Rll tt w my lso dnot t pt s v v... v l+. Gvn two vrts u, v V, sortst pt from u to v s pt from u to v tt s t mnmum lnt mon ll t pts from u to v. If v s unrbl from u, tn t sortst pt dstn from u to v s.

Exmpl 6 5 0 3 T pt d s lnt. T pt b d f s lnt 8. T sond pt s sortst pt from to.

Snl Sour Sortst Pt (SSSP) wt Postv Wts Lt (G, w) wt G = (V, E) b drtd wtd rp, wr w mps vry d of E to postv vlu. Gvn vrtx s n V, t ol of t SSSP problm s to fnd, for vry otr vrtx t V \ {s}, sortst pt from s to t, unlss t s unrbl from s.

A Subsqun Proprty Lmm: If v v... v l+ s sortst pt from v to v l+, tn for vry, j stsfyn < j l +, v v +... v j s sortst pt from v to v j. Proof: Suppos tt ts s not tru. Tn, w n fnd sortr pt to o from v to v j. Usn ts pt to rpl t ornl pt from v to v j ylds sortr pt from v to v l+, w ontrdts t ft tt v v... v l+ s sortst pt.

Exmpl 6 5 0 3 Sn b d f s sortst pt, w know tt ny subsqun of of ts pt s lso sortst pt. For xmpl, b d must b sortst pt from b to.

Nxt, w wll frst xpln ow to solv t SSSP problm wn t nput rp G s DAG. Utlzn t subsqun proprty, our lortm wll output sortst pt tr tt nods ll t sortst pts from t sour vrtx s.

T Ed Rlxton Id For vry vrtx v V, w wll t ll tms mntn vlu dst(v) tt s urntd to b n uppr bound of t sortst pt dstn from s to v. At t nd of t lortm, w wll nsur tt vry dst(v) quls t prs sortst pt dstn from s to v. A or oprton n our lortm s lld d rlxton: Gvn n d (u, v), w rlx t s follows: - If dst(v) < dst(u) + w(u, v), do notn; - Otrws, rdu dst(v) to dst(u) + w(u, v).

T Rlxton Lmm Lmm: dst(v) s stll n uppr bound of t sortst pt dstn form s to v ftr t rlxton. Proof: It suffs to prov tt t sortst pt from s to v nnot v lnt rtr tn dst(u) + w(u, v). T vlu of dst(u) ndts t xstn of pt from s to u wos dstn s t most dst(u). W n trfor o from s to v by frst tkn tt pt to o to u, nd tn r v by rossn t d (u, v). Ts vs us pt from s to v wos dstn s t most dst(u) + w(u, v).

SSSP Alortm on DAG Obtn topolol ordr L on G St dst(s) = 0, nd dst(v) = for ll otr vrts v V 3 St prnt(v) = nl for ll vrts v V 4 Rmov ll t vrts n L tt r bfor s 5 Rpt t follown untl L s mpty: 5. rmov t frst vrtx u of L /* nxt w rlx ll t outon ds of u */ 5. for vry outon d (u, v) of u 5.. f dst(v) > dst(u) + w(u, v) tn st dst(v) = dst(u) + w(u, v), nd prnt(v) = u

Exmpl Suppos tt t sour vrtx s. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d nl nl f nl nl nl nl Frst, obtn n rbtrry topolol ordr,.., L = (, b,,, d,,, f, ). Intlz dst(v) nd prnt(v). Rmov ll vrts bfor n L, ftr w L = (,, d,,, f, ).

Exmpl Rlx ll t outon ds of. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 0 f nl nl nl nl L = (, d,,, f, ).

Exmpl Rlx ll t outon ds of. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 0 f nl nl nl nl L = (d,,, f, ).

Exmpl Rlx ll t outon ds of d. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 7 d f nl 3 d nl nl L = (,, f, ).

Exmpl Rlx ll t outon ds of. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 7 d f 5 3 d nl 4 L = (, f, ).

Exmpl Rlx ll t outon ds of. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 7 d f 5 3 d nl 4 L = (f, ).

Exmpl Rlx ll t outon ds of f. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 6 f f 5 3 d nl 4 L = ().

Exmpl Rlx ll t outon ds of. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 6 f f 5 3 d nl 4 L = (). At ts pont, w v omputd t sortst pt dstns from to ll t otr vrts.

Construtn t Sortst Pt Tr For vry vrtx v, f u = prnt(v) s not nl, tn mk v ld of u. Exmpl 6 5 0 3 vrtx v b d f prnt(v) nl nl nl f d nl sortst pt tr f d

Tm Anlyss Stp (on Sld 30) n on n O( V + E ) tm (DFS). Stps -4 obvously tk O( V ) tm. Rrdn Stp 5, not tt vry outon d s rlxd only on. Sn rlxton tks only O() tm, w know tt Stp 5 n b mplmntd n O( V + E ) tm (O() tm spnt rmovn vrtx from L). Construtn t sortst pt tr t t nd obvously tks O( V ) tm. Ovrll t lortm runs n O( V + E ) tm (w s optml).

W now prov tt our lortm s orrt. In prtulr, w wll prov tt wn t lortm fnss, dst(v) olds t orrt sortst pt dstn from s to v. Strtly spkn, w lso nd to prov tt t flds of prnt(v) llow us to onstrut t sortst pt tr orrtly, but ts s ssntlly smpl orollry of t bov lm (nd s lft for you).

Corrtnss Not tt dst(v) wll nvr n ftr v s rmovd from L (nd s ts out-on ds rlxd). W wll prov: Lmm: Wn dst(v) s rmovd from L, dst(v) quls t sortst pt dstn from s to v. T lmm s suffnt for stblsn t orrtnss of our lortm.

Corrtnss Proof: Rll tt t t bnnn of t lortm, w drtly rmov ll t vrts v tt prd s n L, lvn dst(v) =. Ts s orrt bus non of tos vrts r rbl from s (by dfnton of topolol ordr). W wll prov tt t lmm lso olds for t otr vrts. W wll do so by nduton on t ordr tt vrts r rmovd from L, strtn from s. Bs Cs: Wn s s rmovd, dst(s) = 0, s rqurd by t lmm.

Corrtnss Proof (ont.): Indutv Cs: Suppos tt w r rmovn v from L, nd tt t lmm olds on ll t vrts rmovd bfor v. Lt π b sortst pt from s to v, nd u t vrtx on π mmdtly bfor v. It tus follows tt u must b bfor v n L, nd n, must v bn rmovd. It follows tt dst(u) must b t sortst pt dstn from s to u. Tus, by rlxn d (u, v), t lortm nsurs tt dst(v) nnot b r tn dst(u) + w(u, v), w s xtly t sortst pt dstn from s to v. Tn t lmm follows from t ft tt dst(v) lwys rmns n uppr bound of t sortst pt dstn (t rlxton lmm).

Nxt, w wll xtnd t bov lortm to solv t SSSP problm wn t nput rp G s nrl drtd rps (.., yls my xst). T mjor dffrn s t ordr tt vrts r prossd (rll tt yl rp s no topolol ordrs). T xtndd lortm s lld Djkstr s lortm.

T Ed Rlxton Id Sm d s bfor! For vry vrtx v V, w wll t ll tms mntn vlu dst(v) tt s urntd to b n uppr bound of t sortst pt dstn from s to v. At t nd of t lortm, w wll nsur tt vry dst(v) quls t prs sortst pt dstn from s to v. Ed rlxton: Gvn n d (u, v), w rlx t s follows: - If dst(v) < dst(u) + w(u, v), do notn; - Otrws, rdu dst(v) to dst(u) + w(u, v). T rlxton lmm stll olds.

Djkstr s Alortm St prnt(v) = nl for ll vrts v V St dst(s) = 0, nd dst(v) = for ll otr vrts v V 3 St S = V 4 Rpt t follown untl S s mpty: 5. Rmov from S t vrtx u wt t smllst dst(u). /* nxt w rlx ll t outon ds of u */ 5. for vry outon d (u, v) of u 5.. f dst(v) > dst(u) + w(u, v) tn st dst(v) = dst(u) + w(u, v), nd prnt(v) = u

Exmpl Suppos tt t sour vrtx s. 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d nl nl f nl nl nl nl S = {, b,, d,, f,,, }.

Exmpl Rlx t out-on ds of (bus dst() s t smllst n S): 6 5 0 3 vrtx v dst(v) prnt(v) nl b nl 0 nl d 0 f nl nl nl nl S = {, b, d,, f,,, }. Not tt s bn rmovd!

Exmpl Rlx t out-on ds of d (bus dst(d) s t smllst n S): 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b nl 0 nl d 0 f nl 3 d nl nl S = {, b,, f,,, }.

Exmpl Rlx t out-on ds of : 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b nl 0 nl d 0 f 5 3 d nl 4 S = {, b,, f,, }.

Exmpl Rlx t out-on ds of : 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b nl 0 nl d 0 f 5 3 d nl 4 S = {, b,, f, }.

Exmpl Rlx t out-on ds of f : 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b nl 0 nl d 6 f f 5 3 d nl 4 S = {, b,, }.

Exmpl Rlx t out-on ds of : 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b nl 0 nl d 6 f f 5 3 d nl 4 S = {, b, }.

Exmpl Rlx t out-on ds of : 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b 9 0 nl d 6 f f 5 3 d nl 4 S = {b, }.

Exmpl Rlx t out-on ds of b: 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b 9 0 nl d 6 f f 5 3 d nl 4 S = {}.

Exmpl Rlx t out-on ds of : 6 5 0 3 vrtx v dst(v) prnt(v) 8 d b 9 0 nl d 6 f f 5 3 d nl 4 S = {}. All t sortst pt dstns r now fnl.

Construtn t Sortst Pt Tr For vry vrtx v, f u = prnt(v) s not nl, tn mk v ld of u. Exmpl 6 5 0 3 vrtx v b d f prnt(v) d nl f d nl sortst pt tr f d b

Corrtnss nd Runnn Tm It wll b lft s n xrs for you to prov tt Djkstr s lortm s orrt (by xtndn t orrtnss of our DAG lortm). Just s qully nstrutv s n xrs for you to mplmnt Djkstr s lortm n O(( V + E ) lo V ) tm. You v lrdy lrnd ll t dt struturs for ts purpos. Now t s t tm to prt pplyn tm.

Ts onluds our dsusson on t SSSP problm. W v lrnd ow to solv t problm n 3 sttns: Unt wt for ll ds nd rbtrry rps: BFS, runnn tm O( V + E ). Arbtrry wts nd DAGs: T frst lortm n ts ltur, runnn tm O( V + E ). Postv wts nd rbtrry rps: Djkstr s, runnn tm O(( V + E ) lo V ). Rmrk: Usn n dvnd dt strutur (lld t Fbon Hp) tt wll not b ovrd n ts ours, w n tully mprov t runnn tm of Djkstr s lortm to O( V lo V + E ).