lecture 13 cse 331 oct 2, 2009. announcements please turn in your hw 3 graded hw2, solutions to hw...
Post on 20-Dec-2015
215 views
TRANSCRIPT
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!
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
Start with R = {s}
While exists (u,v) edge v not in R and u in R
Add v to R
Output R
Induction on number of iterations
Base CaseBase Case
I.H.: u is connected to s
I.H.: u is connected to s
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
11
22 33
44 55
66
77
88
11
22
44
55
66 33
88
77
Every non-tree edge is between a
node and its ancestor
Every non-tree edge is between a
node and its ancestor
DFS treeDFS tree
Connected components are disjoint
Either Connected components of s and t are the same or are disjoint
Algorithm to compute ALL the connected
components?
Algorithm to compute ALL the connected
components?
Run BFS on some node s. Then run BFS on t that is not connected to s Run BFS on some node s. Then run BFS on t that is not connected to s