Graph Search Algorithms CSE

Similar documents
Graph Search Algorithms

Lecture 20: Minimum Spanning Trees (CLRS 23)

Graphs Depth First Search

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

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

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

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

5/1/2018. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding Trees. Huffman Coding 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.

Planar convex hulls (I)

Applications of trees

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

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

(Minimum) Spanning Trees

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

CS 103 BFS Alorithm. Mark Redekopp

Minimum Spanning Trees

Strongly connected components. Finding strongly-connected components

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

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)

The University of Sydney MATH 2009

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

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

Graphs Breadth First Search

Lecture II: Minimium Spanning Tree Algorithms

On Hamiltonian Tetrahedralizations Of Convex Polyhedra

Closed Monochromatic Bishops Tours

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

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

SAMPLE CSc 340 EXAM QUESTIONS WITH SOLUTIONS: part 2

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

Single Source Shortest Paths (with Positive Weights)

Outlines: Graphs Part-4. Applications of Depth-First Search. Directed Acyclic Graph (DAG) Generic scheduling problem.

Minimum Spanning Trees

In which direction do compass needles always align? Why?

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

Analysis of Algorithms - Elementary graphs algorithms -

CHELOURANYAN CALENDAR FOR YEAR 3335 YEAR OF SAI RHAVË

L.3922 M.C. L.3922 M.C. L.2996 M.C. L.3909 M.C. L.5632 M.C. L M.C. L.5632 M.C. L M.C. DRIVE STAR NORTH STAR NORTH NORTH DRIVE

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

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

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

2 Trees and Their Applications

Computer Graphics. Viewing & Projections

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

Minimum Spanning Trees

Analysis of Algorithms - Elementary graphs algorithms -

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

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

FL/VAL ~RA1::1. Professor INTERVI of. Professor It Fr recru. sor Social,, first of all, was. Sys SDC? Yes, as a. was a. assumee.

Differentiation of allergenic fungal spores by image analysis, with application to aerobiological counts

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

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

23 Minimum Spanning Trees

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

1.9 Cartesian Tensors

An action with positive kinetic energy term for general relativity. T. Mei

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

P a g e 3 6 of R e p o r t P B 4 / 0 9

Sheet Title: Building Renderings M. AS SHOWN Status: A.R.H.P.B. SUBMITTAL August 9, :07 pm

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

Walk Like a Mathematician Learning Task:

Minimum Spanning Trees (CLRS 23)

0# E % D 0 D - C AB

SAMPLE LITANY OF THE SAINTS E/G. Dadd9/F. Aadd9. cy. Christ, have. Lord, have mer cy. Christ, have A/E. Dadd9. Aadd9/C Bm E. 1. Ma ry and. mer cy.

Ash Wednesday. First Introit thing. * Dómi- nos. di- di- nos, tú- ré- spi- Ps. ne. Dó- mi- Sál- vum. intra-vé-runt. Gló- ri-

Examples and applications on SSSP and MST

Telecommunications BUILDING INTERCOM CALL BUTTON WITH 3/4"C AND PULL STRING TO ACCESSIBLE CEILING SPACE. MOUNT 48" AFF.

P a g e 5 1 of R e p o r t P B 4 / 0 9

Priority Search Trees - Part I

w x a f f s t p q 4 r u v 5 i l h m o k j d g DT Competition, 1.8/1.6 Stainless, Black S, M, L, XL Matte Raw/Yellow

VLSI Testing Assignment 2

(4, 2)-Choosability of Planar Graphs with Forbidden Structures

T h e C S E T I P r o j e c t

10. EXTENDING TRACTABILITY

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

ADORO TE DEVOTE (Godhead Here in Hiding) te, stus bat mas, la te. in so non mor Je nunc. la in. tis. ne, su a. tum. tas: tur: tas: or: ni, ne, o:

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

Housing Market Monitor

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

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

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

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

CAVALIER SPA & SALON UPFIT

Strongly Connected Components

SAN JOSE CITY COLLEGE PHYSICAL EDUCATION BUILDING AND RENOVATED LAB BUILDING SYMBOL LIST & GENERAL NOTES - MECHANICAL

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

Wave Phenomena Physics 15c

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

ELECTRONIC SUPPLEMENTARY INFORMATION

BASIC CAGE DETAILS SHOWN 3D MODEL: PSM ASY INNER WALL TABS ARE COINED OVER BASE AND COVER FOR RIGIDITY SPRING FINGERS CLOSED TOP

Fuzzy Reasoning and Optimization Based on a Generalized Bayesian Network

I M P O R T A N T S A F E T Y I N S T R U C T I O N S W h e n u s i n g t h i s e l e c t r o n i c d e v i c e, b a s i c p r e c a u t i o n s s h o

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

A ' / 1 6 " 5 ' / 4 " A4.2 48' - 0" 3 12' - 7" 13' - 11" 10' - 0" 9' - 0" 2' - 6" 1. 2: 12 INDICATES SHOW MELT TYP ABV ABV

Dental PBRN Study: Reasons for replacement or repair of dental restorations

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

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

Transcription:

Grp Src Aortms 1

Grp b No ~ cty or computr E ~ ro or t cb c Unrct or Drct A surprsny r numbr o computton probms cn b xprss s rp probms. 2

Drct n Unrct Grps () A rct rp G = (V, E), wr V = {1,2,3,4,5,6} n E = {(1,2), (2,2), (2,4), (2,5), (4,1), (4,5), (5,4), (6,3)}. T (2,2) s s-oop. (b) An unrct rp G = (V,E), wr V = {1,2,3,4,5,6} n E = {(1,2), (1,5), (2,5), (3,6)}. T vrtx 4 s sot. (c) T subrp o t rp n prt () nuc by t vrtx st {1,2,3,6}. 3

Trs Tr Forst Grp wt Cyc A tr s connct, cycc, unrct rp. A orst s st o trs (not ncssry connct) 4

Runnn Tm o Grp Aortms Runnn tm otn uncton o bot V n E. For convnnc, rop t. n symptotc notton,.. O(V+E). 5

En o Lctur 10 Apr 6, 2009

Rprsnttons: Unrct Grps Spc compxty: Tm to n nbours o vrtx u : Acncy Lst θ ( V + E) θ (r( u)) Acncy Mtrx 2 θ ( V ) θ ( V ) Tm to trmn ( uv, ) E: θ (r( u)) 7 θ (1)

Rprsnttons: Drct Grps Spc compxty: Tm to n nbours o vrtx u : Acncy Lst θ ( V + E) θ (r( u)) Acncy Mtrx 2 θ ( V ) θ ( V ) Tm to trmn ( uv, ) E: θ (r( u)) 8 θ (1)

Brt-Frst Src Go: To rcovr t sortst pts rom sourc no s to otr rcb nos v n rp. T nt o c pt n t pts tmsvs r rturn. Nots: Tr r n xponnt numbr o possb pts Ts probm s rr or nr rps tn trs bcus o cycs!? 9 s

Brt-Frst Src Input: Grp G = ( V, E ) (rct or unrct) n sourc vrtx s V. Output: v [ ] = sortst pt stnc δ ( sv, ) rom sto v, v V. π[ v] = u suc tt ( u, v) s st on sortst pt rom s to v. I: sn out src wv rom s. Kp trc o prorss by coourn vrtcs: Unscovr vrtcs r coour bc Just scovr vrtcs (on t wvront) r coour r. Prvousy scovr vrtcs (bn wvront) r coour ry. 10

s BFS Frst-In Frst-Out (FIFO) quu stors ust scovr vrtcs b Foun Not Hn Quu c m 11

c s BFS =0 b m Foun Not Hn Quu s =0 12

c s BFS =0 =1 b m Foun Not Hn Quu =0 =1 b 13

c s BFS =0 =1 b m Foun Not Hn Quu b =1 14

c s BFS =0 =1 b m Foun Not Hn Quu =2 b c =1 =2 15

c s BFS =0 =1 b m Foun Not Hn Quu =2 b c m =1 =2 16

c s BFS =0 =1 b m Foun Not Hn Quu =2 b c m =1 =2 17

c s BFS =0 =1 b m Foun Not Hn Quu =2 c m =1 =2 18

c s BFS =0 =1 b m Foun Not Hn Quu =2 c m =2 19

c s BFS =0 =1 b 20 m =3 Foun Not Hn Quu =2 m =2 =3

c s BFS =0 =1 b 21 m =3 Foun Not Hn Quu =2 m =2 =3

c s BFS =0 =1 b 22 m =3 Foun Not Hn Quu =2 =2 =3

c s BFS =0 =1 b 23 m =3 Foun Not Hn Quu =2 =2 =3

c s BFS =0 =1 b 24 m =3 Foun Not Hn Quu =2 =2 =3

c s BFS =0 =1 b 25 m =3 Foun Not Hn Quu =2 =3

c s =4 BFS =0 =1 b 26 m =3 Foun Not Hn Quu =2 =3 =4

c s =4 BFS =0 =1 b 27 m =3 Foun Not Hn Quu =2 =3 =4

c s =4 BFS =0 =1 b 28 m =3 Foun Not Hn Quu =2 =3 =4

c s =4 BFS =0 =1 b 29 m =3 Foun Not Hn Quu =2 =4

c s =4 BFS =0 =1 b 30 m =3 Foun Not Hn Quu =2 =4 =5

Brt-Frst Src Aortm Q s FIFO quu. BLACK Ec vrtx ssn nt vu t most onc. RED Q contns vrtcs wt vus {,,, +1,, +1} vus ssn r monotoncy ncrsn ovr tm. BLACK RED GRAY 31

Brt-Frst-Src s Gry Vrtcs r n: n orr o tr scovry (FIFO quu) Smst vus rst 32

Corrctnss Bsc Stps: s u v T sortst pt to u s nt & tr s n rom u to v Tr s pt to v wt nt +1. 33

Corrctnss Vrtcs r scovr n orr o tr stnc rom t sourc vrtx s. Wn w scovr v, ow o w now tr s not sortr pt to v? Bcus tr ws, w wou ry v scovr t! s u v 34

Corrctnss Input: Grp G = ( V, E ) (rct or unrct) n sourc vrtx s V. Output: v [] = stnc rom sto v, v V. π[ v] = u suc tt ( u, v) s st on sortst pt rom s to v. Two-stp proo: On xt: 1. v [ ] δ ( sv, ) v V 2. v [ ] > δ ( sv, ) v V 35

Cm 1. s nvr too sm: [ v] δ ( s, v) v V Proo: Tr xsts pt rom s to v o nt [ v]. By Inucton: Suppos t s tru or vrtcs tus r scovr ( r n ry). v s scovr rom som cnt vrtx u bn n. v [ ] = u [ ] + 1 δ (, s u) + 1 δ (, sv) s u v snc c vrtx v s ssn vu xcty onc, t oows tt o n xt, v [ ] δ ( s, v) v V. 36

Cm 1. s nvr too sm: [ v] δ ( s, v) v V Proo: Tr xsts pt rom s to v o nt [ v]. BLACK RED s u v <LI>: v [ ] δ ( sv, ) 'scovr' ( r or r y) v V BLACK RED δ ( su, ) + 1 δ ( sv, ) GRAY 37

Cm 2. s nvr too b: [ v] δ ( s, v) v V Proo by contrcton: Suppos on or mor vrtcs rcv vu rtr tn δ. Lt v b t vrtx wt mnmum δ ( s, v) tt rcvs suc vu. Suppos tt v s scovr n ssn ts vu wn vrtx x s quu. Lt u b v's prcssor on sortst pt rom s to v. Tn δ (, s v) < [] v δ (, s v) 1 < [] v 1 u [ ] < x [ ] s x [ ] = v [ ] 1 [ u] = δ ( s, v ) 1 x u v Rc: vrtcs r quu n ncrsn orr o v u. u ws quu bor x. [ v] = [ u] + 1 =δ ( s, v) Contrcton! 38

Corrctnss Cm 1. s nvr too sm: [ v] δ ( s, v) v V Cm 2. s nvr too b: [ v] δ ( s, v) v V s ust rt: [ v] = δ ( s, v) v V 39

Prorss? On vry trton on vrtx s procss (turns ry). BLACK RED BLACK RED GRAY 40

Runnn Tm Ec vrtx s nquu t most onc OV ( ) Ec ntry n t cncy sts s scnn t most onc O(E) Tus run tm s OV ( + E). BLACK RED BLACK RED GRAY 41

Optm Substructur Proprty T sortst pt probm s t optm substructur proprty: Evry subpt o sortst pt s sortst pt. sortst pt s u v sortst pt sortst pt T optm substructur proprty s mr o bot ry n ynmc prormmn ortms. ows us to comput bot sortst pt stnc n t sortst pts tmsvs by storn ony on vu n on prcssor vu pr vrtx. 42

Rcovrn t Sortst Pt For c no v, stor prcssor o v n π(v). s u π(v) v Prcssor o v s π(v) = u. 43

Rcovrn t Sortst Pt PRINT-PATH( G, s, v ) Prconton: s n v r vrtcs o rp G Postconton: t vrtcs on t sortst pt rom s to v v bn prnt n orr v = s tn prnt s s π[] v = NI L tn prnt " no pt rom" s "to" v "xsts" s PRINT-PATH( G, s, π[ v]) prnt v 44

Coours r ctuy not rqur 45

Dpt Frst Src (DFS) I: Contnu srcn pr nto t rp, unt w t stuc. I t s vn v v bn xpor w bctrc to t vrtx rom wc v ws scovr. Dos not rcovr sortst pts, but cn b usu or xtrctn otr proprts o rp,.., Topooc sorts Dtcton o cycs Extrcton o strony connct componnts 46

Dpt-Frst Src Inp u t: Grp G = ( V, E ) (rct or unrct) Output: 2 tmstmps on c vrtx: v [] = scovry tm. v [] = nsn tm. Expor vry, strtn rom rnt vrtcs ncssry. As soon s vrtx scovr, xpor rom t. Kp trc o prorss by coourn vrtcs: Bc: unscovr vrtcs 1 v [ ] < v [ ] 2 V R: scovr, but not ns (st xporn rom t) Gry: ns (oun vrytn rcb rom t). 47

DFS s Not: Stc s Lst-In Frst-Out (LIFO) b Foun Not Hn Stc <no,# s> c 48 m

s 1 DFS b Foun Not Hn Stc <no,# s> c 49 m s,0

2 s 1 DFS b Foun Not Hn Stc <no,# s> c 50 m,0 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 51 m c,0,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 4 52 m,0 c,1,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 4 5 53 m,0,1 c,1,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c Pt on Stc 4 Tr E 56 54 m,1 c,1,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 55 m c,1,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 56 m,0 c,2,1 s,1

Cross E to n no: []<[] 3 c 47 2 8 56 s 1 DFS 57 b m Foun Not Hn Stc <no,# s>,1 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 58 m,2 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 59 9 m,0,3 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 60 9 m,1,3 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 61 910 m,3 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 11 62 910 m,0,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 11 63 910 m 12,0,1,4 c,2,1 s,1

Bc E to no on Stc: 2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 8 56 11 64 910 m 12,1,1,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 11 65 910 m 13 12 m,0,2,1,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 11 66 910 m 13 12 m,1,2,1,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 11 67 910 m 12 1314,2,1,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 11 68 910 m 1215 1314,1,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 56 8 1116 69 910 m 1215 1314,4 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 17 56 8 1116 70 910 m 1215 1314,0,5 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 17 56 8 1116 71 910 m 1215 1314,1,5 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 1718 56 8 1116 72 910 m 1215 1314,5 c,2,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 1718 56 819 1116 73 910 m 1215 1314 c,2,1 s,1

Forwr E 2 s 1 DFS b Foun Not Hn Stc <no,# s> 3 c 47 1718 56 819 1116 74 910 m 1215 1314 c,3,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 1116 75 910 m 1215 1314,1 s,1

2 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 1116 76 910 m 1215 1314,2 s,1

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 1116 77 910 m 1215 1314 s,1

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 21 1116 78 910 m 1215 1314,0 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 21 1116 79 910 m 1215 1314,1 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 21 1116 80 910 m 1215 1314,2 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 21 1116 81 910 m 22 1215 1314,0,3 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 21 1116 82 910 m 22 1215 1314,1,3 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1718 56 819 21 1116 83 910 m 2223 1215 1314,3 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 84 910 m 2223 1215 1314 s,2

220 s 1 DFS b Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 85 910 m 2223 1215 1314 s,3

220 s 1 DFS b 25 Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 86 910 m 2223 1215 1314 b,0 s,4

220 s 1 DFS b 25 Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 87 910 m 2223 1215 1314 b,1 s,4

220 s 1 DFS b 25 Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 88 910 m 2223 1215 1314 b,2 s,4

220 s 1 DFS b 25 Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 89 910 m 2223 1215 1314 b,3 s,4

220 s 1 DFS b 2526 Foun Not Hn Stc <no,# s> 319 c 47 1116 1718 56 819 2124 90 910 m 2223 1215 1314 s,4

319 c 47 Tr Es Bc Es Forwr Es Cross Es 220 1718 56 819 s 127 2124 DFS 1116 91 Fns! 910 b 2526 m Foun Not Hn Stc <no,# s> 2223 1215 1314

Csscton o Es n DFS 1. Tr s r s n t pt-rst orst G π. E (u, v) s tr v ws rst scovr by xporn (u, v). 2. Bc s r tos s (u, v) connctn vrtx u to n ncstor v n pt-rst tr. 3. Forwr s r non-tr s (u, v) connctn vrtx u to scnnt v n pt-rst tr. 4. Cross s r otr s. Ty cn o btwn vrtcs n t sm pt-rst tr, s on s on vrtx s not n ncstor o t otr. 319 c 47 220 1718 56 819 s 127 2124 1116 b 2526 m 2223 1215 1314 92 910

Csscton o Es n DFS 1. Tr s: E (u, v) s tr v ws bc wn (u, v) trvrs. 2. Bc s: (u, v) s bc v ws r wn (u, v) trvrs. 3. Forwr s: (u, v) s orwr v ws ry wn (u, v) trvrs n [v] > [u]. 4. Cross s (u,v) s cross v ws ry wn (u, v) trvrs n [v] < [u]. Cssyn s cn p to nty proprts o t rp,.., rp s cycc DFS ys no bc s. 319 c 47 220 1718 56 819 s 127 2124 1116 b 2526 m 2223 1215 1314 93 910

Unrct Grps In pt-rst src o n unrct rp, vry s tr tr or bc. Wy? 94

Unrct Grps Suppos tt (u,v) s orwr or cross n DFS o n unrct rp. (u,v) s orwr or cross wn v s ry n (ry) wn ccss rom u. Ts mns tt vrtcs rcb rom v v bn xpor. Snc w r currnty nn u, u must b r. Cry v s rcb rom u. Snc t rp s unrct, u must so b rcb rom v. Tus u must ry v bn n: u must b ry. Contrcton! u v 95

En o Lctur 11 Apr 8, 2009

DFS(G) Dpt-Frst Src Aortm BLACK BLACK DFS-Vst ( u ) Prconton: vrtx u s unscovr Postconton: vrtcs rcb rom u v bn procss RED BLACK BLACK GRAY GRAY 97

DFS(G) Dpt-Frst Src Aortm BLACK tot wor = θ( V ) BLACK Tus runnn tm = θ ( V + E ) DFS-Vst ( u ) Prconton: vrtx u s unscovr Postconton: vrtcs rcb rom u v bn procss RED BLACK BLACK tot wor = A[ v ] = θ( E ) v V GRAY GRAY 98

Topooc Sortn (.., puttn tss n nr orr) An ppcton o Dpt-Frst Src

Lnr Orr unrwr socs pnts sos unrwr pnts socs sos 100 socs unrwr pnts sos

Lnr Orr unrwr socs pnts sos Too mny vo ms? 101

Lnr Orr b c Prconton: A Drct Acycc Grp (DAG) Post Conton: Fn on v nr orr Aortm: Fn trmn no (sn). Put t st n squnc. Dt rom rp & rpt Θ(V) Θ(V 2 ) 102.. W cn o bttr!

b c Lnr Orr A: DFS Foun Not Hn Stc 103..

b c Lnr Orr A: DFS 104 Foun Not Hn Stc Wn no s popp o stc, nsrt t ront o nry-orr to o st. Lnr Orr:..

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: 105,

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: 106,,

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: 107,,,

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: 108,,,,

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: 109,,,,

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: 110,,,,,

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr:,,,,,, 111

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr:,,,,,,, 112

b c Lnr Orr A: DFS Foun Not Hn Stc c b Lnr Orr:,,,,,,, 113

b c Lnr Orr A: DFS Foun Not Hn Stc b Lnr Orr: c,,,,,,,, 114

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: b,c,,,,,,,, 115

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr: b,c,,,,,,,, 116

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr:,b,c,,,,,,,, 117

b c Lnr Orr A: DFS Foun Not Hn Stc Lnr Orr:,,b,c,,,,,,,, Don! 118

u v Lnr Orr Proo: Consr c Cs 1: u os on stc rst bor v. Bcus o, v os on bor u coms o v coms o bor u coms o v os tr u n orr. Foun Not Hn Stc u v 119 u v

u v Lnr Orr Proo: Consr c Cs 1: u os on stc rst bor v. Cs 2: v os on stc rst bor u. v coms o bor u os on. v os tr u n orr. Foun Not Hn Stc u v 120 u v

Lnr Orr Proo: Consr c Cs 1: u os on stc rst bor v. Cs 2: v os on stc rst bor u. v coms o bor u os on. Cs 3: v os on stc rst bor u. u os on bor v coms o. Pnc: u os tr v n orr. Cyc mns nr orr s mpossb Foun Not Hn Stc u v T nos n t stc orm pt strtn t s. u v v u 121

b c Lnr Orr A: DFS Anyss: Θ(V+E) Foun Not Hn Stc Lnr Orr:,,b,c,,,,,,,, Don! 122

Sortst Pts Rvst

Bc to Sortst Pt BFS ns t sortst pts rom sourc no s to vry vrtx v n t rp. Hr, t nt o pt s smpy t numbr o s on t pt. But wt s v rnt costs? s δ (, sv) = 3 δ (, sv) = 12 v s 1 2 3 7 2 5 v 124

Sn-Sourc (Wt) Sortst Pts

T Probm Wt s t sortst rvn rout rom Toronto to Ottw? (.. MAPQust, Goo Mps) Input: Drct Grp G = ( V, E) E wts w : E Wt o pt p =< v, v,..., v > = w( v, v) 0 1 1 = 1 Sortst-pt wt rom u to v : p δ ( uv, ) = mn{ w( p) : u v} pt u v, otrws. Sortst pt rom u to v s ny pt p suc tt w( p) = δ ( u, v). 126

Exmp Sn-sourc sortst pt src nucs src tr root t s. Ts tr, n nc t pts tmsvs, r not ncssry unqu. 127

Sortst pt vrnts Sn-sourc sortst-pts probm: t sortst pt rom s to c vrtx v. (.. BFS) Sn-stnton sortst-pts probm: Fn sortst pt to vn stnton vrtx t rom c vrtx v. Sn-pr sortst-pt probm: Fn sortst pt rom u to v or vn vrtcs u n v. A-prs sortst-pts probm: Fn sortst pt rom u to v or vry pr o vrtcs u n v. 128

Ntv-wt s OK, s on s no ntv-wt cycs r rcb rom t sourc. I w v ntv-wt cyc, w cn ust p on roun t, n t w(s, v) = or v on t cyc. But OK t ntv-wt cyc s not rcb rom t sourc. Som ortms wor ony tr r no ntv-wt s n t rp. 129

Optm substructur Lmm: Any subpt o sortst pt s sortst pt Proo: Cut n pst. Suppos ts pt p s sortst pt rom u to v. Tn δ ( u, v) = w( p) = w( p ) + w( p ) + w( p ). Now suppos tr xsts sortr pt x y. Tn w( p ) < w( p ). xy Construct p : xy ux xy yv Tn w( p ) = w( p ) + w( p ) + w( p ) < w( p ) + w( p ) + w( p ) = w( p). ux xy yv So p wsn't sortst pt tr! p xy ux xy yv 130

Cycs Sortst pts cn t contn cycs: Ary ru out ntv-wt cycs. Postv-wt: w cn t sortr pt by omttn t cyc. Zro-wt: no rson to us tm ssum tt our soutons won t us tm. 131

Output o sn-sourc sortst-pt ortm For c vrtx v n V: [v] = δ(s, v). Inty, [v]=. Ruc s ortm prorsss. But wys mntn [v] δ(s, v). C [v] sortst-pt stmt. π[v] = prcssor o v on sortst pt rom s. I no prcssor, π[v] = NIL. π nucs tr sortst-pt tr. 132

Intzton A sortst-pts ortms strt wt t sm ntzton: INIT-SINGLE-SOURCE(V, s) or c v n V o [v] π[v] NIL [s] 0 133

Rxn n Cn w mprov sortst-pt stmt or v by on trou u n tn (u,v)? RELAX(u, v,w) [v] > [u] + w(u, v) tn [v] [u] + w(u, v) π[v] u 134

Gnr sn-sourc sortst-pt strty 1. Strt by cn INIT-SINGLE-SOURCE 2. Rx Es Aortms r n t orr n wc s r tn n ow mny tms c s rx. 135

Exmp: Sn-sourc sortst pts n rct cycc rp (DAG) Snc rp s DAG, w r urnt no ntv-wt cycs. 136

Aortm Tm: Θ ( V + E) 137

Exmp 138

Exmp 139

Exmp 140

Exmp 141

Exmp 142

Exmp 143

Corrctnss: Pt rxton proprty (Lmm 24.15) Lt p =< v, v,..., v > b sortst pt rom s = v to v. 0 1 0 I w rx, n orr, ( v, v ), ( v, v ),..., ( v, v ), 0 1 1 2-1 vn ntrmx wt otr rxtons, tn v [ ] = δ ( s, v). 144

Corrctnss o DAG Sortst Pt Aortm Bcus w procss vrtcs n topoocy sort orr, s o ny pt r rx n orr o pprnc n t pt. Es on ny sortst pt r rx n orr. By pt-rxton proprty, corrct. 145

Exmp: Dstr s ortm Apps to nr wt rct rp (my contn cycs). But wts must b non-ntv. Essnty wt vrson o BFS. Inst o FIFO quu, uss prorty quu. Kys r sortst-pt wts ([v]). Mntn 2 sts o vrtcs: S = vrtcs wos n sortst-pt wts r trmn. Q = prorty quu = V-S. 146

Dstr s ortm Dstr s ortm cn b vw s ry, snc t wys cooss t tst vrtx n V S to to S. 147

Dstr s ortm: Anyss Anyss: Usn mnp, quu oprtons ts O(oV) tm OV ( ) O(o V ) O( V) trtons Runnn Tm s OE ( o V) O(o V ) O( E) trtons 148

Exmp Ky: Wt Not Foun Gry Hnn Bc Hn 149

Exmp 150

Exmp 151

Exmp 152

Exmp 153

Exmp 154

Corrctnss o Dstr s ortm Loop nvrnt: [v] = δ(s, v) or v n S. Intzton: Inty, S s mpty, so trvy tru. Trmnton: At n, Q s mpty S = V [v] = δ(s, v) or v n V. Mntnnc: N to sow tt [u] = δ(s, u) wn u s to S n c trton. [u] os not cn onc u s to S. 155

Corrctnss o Dstr s Aortm: Uppr Boun Proprty Uppr Boun Proprty: 1. v [ ] δ ( sv, ) v V 2. Onc v [ ] = δ ( sv, ), t osn't cn Proo: By nucton. Bs Cs : v [ ] δ ( sv, ) v V mmty tr ntzton, snc s [ ] = 0 = δ ( ss, ) v [ ] = v s Inuctv Stp: Suppos x [ ] δ ( sx, ) x V Suppos w rx ( uv, ). I v [ ] cns, tn v [ ] = u [ ] + wuv (, ) δ (, su) + wuv (, ) δ (, sv) 156

Corrctnss o Dstr s Aortm C m : Wn u s to S, [ u] = δ ( s, u) Proo by Contrcton: Lt u b t rst vrtx to S suc tt u [ ] δ ( su, ) wn us. Lt y b rst vrtx n V S on sortst pt to u Lt x b t prcssor o y on t sortst pt to u C m: y [ ] = δ ( sy, ) wn us to S. Proo: x [ ] = δ ( sx, ), snc x S. ( x, y) ws rx wn x ws to S y [ ] = δ (, sx) + wxy (, ) = δ (, sy) Hn 157

Corrctnss o Dstr s Aortm Tus y [ ] = δ ( sy, ) wn us to S. y [ ] = δ ( sy, ) δ ( su, ) u [ ] (uppr boun proprty) But u [ ] y [ ] wn u to S Tus y [ ] = δ ( sy, ) = δ ( su, ) = u [ ]! Tus wn u s to S, [ u] = δ ( s, u) Consquncs: Tr s sortst pt to u suc tt t prcssor o u π[ u] S wn u s to S. T pt trou y cn ony b sortst pt w[ p ] = 0. 2 Hn π[ u] 158

Corrctnss o Dstr s ortm Loop nvrnt: [v] = δ(s, v) or v n S. Mntnnc: N to sow tt [u] = δ(s, u) wn u s to S n c trton. [u] os not cn onc u s to S. Rx(u,v,w) cn ony crs v [ ]. By t uppr boun proprty, v [ ] δ ( sv, ). Tus onc v [ ] = δ ( sv, ), t w not b cn.? 159