lecture17

# lecture17 - BFS DFS IE170 Algorithms in Systems Engineering...

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: BFS DFS IE170: Algorithms in Systems Engineering: Lecture 17 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 2, 2007 Jeff Linderoth IE170:Lecture 17 BFS DFS Taking Stock Last Time Depth-First Search This Time: Uses of DFS Topological Sort Strongly Connected Components Jeff Linderoth IE170:Lecture 17 BFS DFS Depth-First Search DFS Input : Graph G = ( V,E ) No source vertex here. Works for undirected and directed graphs. We focus on directed graphs today... Output : Two timestamps for each node d ( v ) , f ( v ) , Output : π ( v ) , predecessor of v not on shortest path necessarily Jeff Linderoth IE170:Lecture 17 BFS DFS DFS (Initialize and Go) dfs ( V,E ) 1 for each u in V 2 do color ( u ) ← green 3 π ( u ) ← nil 4 time ← 5 for each u in V 6 do if color [ u ] = green 7 then dfs-visit ( u ) Jeff Linderoth IE170:Lecture 17 BFS DFS DFS (Visit Node—Recursive) dfs-visit ( u ) 1 color ( u ) ← yellow 2 d [ u ] ← time ++ 3 for each v in Adj [ u ] 4 do if color [ v ] = green 5 then π [ v ] ← u 6 dfs-visit ( v ) 7 8 color ( u ) ← red 9 f [ u ] = time ++ Jeff Linderoth IE170:Lecture 17 BFS DFS Parenthesis Theorem Let’s look at the intervals: [ d [ v ] ,f [ v ]] for each vertex v ∈ V . (Surely, d [ v ] < f [ v ] ) These tell us about the predecessor relationship in G π 1 If I finish exploring u before first exploring v , ( d [ u ] < f [ v ]) then v is not a descendant of u . (Or versa vice) 2 If [ d [ u ] ,f [ u ]] ⊂ [ d [ v ] ,f [ v ]] then u is a descendent of v in the DFS tree 3 If [ d [ v ] ,f [ v ]] ⊂ [ d [ u ] ,f [ u ]] then v is a descendent of u in the DFS tree Jeff Linderoth IE170:Lecture 17 BFS DFS Analysis of DFS Loop on lines 1-3 O ( | V | ) dfs-visit is called exactly once for each vertex v ( Why? ) Because the first thing you do is paint the node yellow The Loop on lines 3-6 in calls dfs-visit | Adj [ v ] | times for vertex v ....
View Full Document

{[ snackBarMessage ]}

### Page1 / 6

lecture17 - BFS DFS IE170 Algorithms in Systems Engineering...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online