Lecture topic-BruteForce

And analysis of algorithms chapter 4 6 depth first

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

View Full Document Right Arrow Icon
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

This note was uploaded on 10/31/2013 for the course RAIK 283 taught by Professor Yinglu during the Fall '12 term at UNL.

Ask a homework question - tutors are online