lecture 13 cse 331 oct 2, 2009. announcements please turn in your hw 3 graded hw2, solutions to hw...

9
Lecture 13 CSE 331 Oct 2, 2009

Post on 20-Dec-2015

215 views

Category:

Documents


2 download

TRANSCRIPT

Lecture 13

CSE 331Oct 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 ComponentConnected 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

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

Read Sec 3.2