{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture topic-BruteForce

# Count 1 mark v with count mark for each vertex w

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: 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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern