Last Time
Both BFS and DFS are 2 ways to find all the connected components in a graph. It doesn’ t matter what node we start at when we look for a connected component. The trees constructed will generally look different based on the algorithm we use and the order in which we visit nodes.
1
Implementing BFS (2)
initialize discovered to false for all nodes add s to the queue R = {s} discovered[s] = true while the queue is not empty { let u be the first node in the queue remove u from the queue for each edge (u, v) { if (!discovered[v]) { add v to the queue R = R ∪ {v} discovered[v] = true } } }