Top Banner
Lecture 13 CSE 331 Oct 2, 2009
9

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.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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.

Lecture 13

CSE 331Oct 2, 2009

Page 2: 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.

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!

Page 3: 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.

Connected ComponentConnected component (of s) is the set of all nodes connected to s

Page 4: 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.

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

Page 5: 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.

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

Page 6: 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.

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

Page 7: 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.

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

Page 8: 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.

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

Page 9: 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.

Read Sec 3.2