15
CSE 2331/5331 Intuition Starting from source node s, Spread a wavefront to visit other nodes First visit all nodes one edge away from s Then all nodes two edges away from s … Need a data-structure to store nodes to be explored.

20
CSE 2331/5331 Summary for BFS Starting from source node s, visits remaining nodes of graph from small distance to large distance This is one way to traverse an input graph With some special property where nodes are visited in non-decreasing distance to the source node s. Return distance between s to any reachable node in time O(|V| + |E|)

21
DFS: Depth-First Search Another graph traversal algorithm BFS: Go as broad as possible in the algorithm DFS: Go as deep as possible in the algorithm CSE 2331/5331

52
Another Example CSE 2331/5331 Is the sorting order unique? Why requires DAG?

53
A topological sorted order of graph G exists if and only if G is a directed acyclic graph (DAG). CSE 2331/5331

54
Question How to topologically sort a given DAG? Intuition: Which node can be the first node in the topological sort order? A node with in-degree 0 ! After we remove this, the process can be repeated. CSE 2331/5331

58
Time complexity O(V+E) Correctness: What if the algorithm terminates before we finish visiting all nodes? Procedure TopologicalSort(G) outputs a sorted list of all nodes if and only if the input graph G is a DAG If G is not DAG, the algorithm outputs only a partial list of vertices. CSE 2331/5331

59
Remarks Other topological sort algorithm by using properties of DFS CSE 2331/5331