close

Session 12

Traversing graph

Tips for Exercises 4

Traversing graph

Example graph

Important notes

We need to avoid infinite loops on cycles

=> We mark visited nodes

We should visit all nodes (not connected graph)

=> Check that you have visited all vertexes

Simple traveling

Depth-first search

Breadth-first search

Depth-first search

Uses recursion

Similar to traversals on trees

Exercise 1

We want to implement DFS method to template class

Exercise 2

We can try to implement BFS to template class

Tips for exercises (chapter 4)