Lecture topic-BruteForce

Count 1 mark v with count mark for each vertex w

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: with 0 if dfs(v) dfs(v) dfs(v) dfs( 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 13 Application: checking graph Application: connectivity and finding connected components components 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 14 Application: checking acyclicity 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 15 Breadth-first search a Explore graph moving across to all the neighbors of last Explore visited vertex visited a Similar to level-by-level tree traversals Similar a Applications: same as DFS, but can also find paths from a Applications: vertex to all other vertices with the smallest number of edges edges Design and Analysis of Algorithms – Chapter 4 16 Example – undirected graph a c d e a b f g h Breadth-first traversal: Design and Analysis of Algorithms – Chapter 4 17 Example – undirected graph a a c d e a b f...
View Full Document

Ask a homework question - tutors are online