Lecture 13 CSE 331 Oct 2, 2009 Announcements Please turn in your HW 3 Graded HW2, solutions to HW 3, HW 4 at the END of the class Maybe extra lectures next week on proofs– check the blog! Connected Component Connected component (of s) is the set of all nodes connected to s Computing Connected Component Start with R = {s} While exists (u,v) edge v not in R and u in R Add v to R Output R R is the connected component of s Claim 1: All vertices in R are connected to s Base Case Induction on number of iterations I.H.: u is connected to s Start with R = {s} While exists (u,v) edge v not in R and u in R Add v to R Output R Today’s agenda If w is not in R then w is not connected to s Depth First Search Computing all connected components Run-time analysis of DFS and BFS A DFS run 1 1 7 2 2 3 8 4 4 Every nontree edge is between a node and its ancestor 5 5 6 DFS tree 6 3 8 7 Connected components are disjoint Either Connected components of s and t are the same or are disjoint Algorithm to compute ALL the connected components? Run BFS on some node s. Then run BFS on t that is not connected to s Read Sec 3.2