{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture topic-BruteForce

# And analysis of algorithms chapter 4 6 depth first

This preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: f “visiting” vertices Design and Analysis of Algorithms – Chapter 4 6 Depth-first search a a Explore graph always moving away from last visited Explore vertex vertex Pseudocode for Depth-first-search of graph G=(V,E) DFS(G) count :=0 mark each vertex with 0 mark (unvisited) (unvisited) for each vertex v∈ V do do if v is marked with 0 if dfs(v) dfs(v) dfs(v) count := count + 1 mark v with count mark for each vertex w adjacent to for v do do if w is marked with 0 if dfs(w) dfs( Design and Analysis of Algorithms – Chapter 4 7 Example – undirected graph a c d e a b f g h dfs(v) count := count + 1 mark v with count mark Depth-first traversal: for each vertex w adjacent to for v do do if w is marked with 0 if dfs( Design and Analysis of Algorithms – Chapterdfs(w) 4 8 Question a How to rewrite the procedure dfs(v), using a stack to How eliminate recursion eliminate dfs(v) count := count + 1 mark v with count mark for each vertex w adjacent to v do for do if w is marked with 0 if dfs(w) dfs( Design and Analysis of Algorithms – Chapter 4 9 Non-recursive version of DFS Non-recursive algorithm a...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online