Lecture 13 CSE 331 Oct 2, 2009. Announcements Mid term in < 2 weeks Graded HW2 at the END of the...

14
Lecture 13 CSE 331 Oct 2, 2009
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    214
  • download

    0

Transcript of Lecture 13 CSE 331 Oct 2, 2009. Announcements Mid term in < 2 weeks Graded HW2 at the END of the...

Lecture 13

CSE 331Oct 2, 2009

Announcements

Mid term in < 2 weeks

Graded HW2 at the END of the class

Breadth First Search (BFS)

Is s connected to t?

Build layers of vertices connected to s

L0 = {s}

Assume L0,..,Lj have been constructed

Lj+1 set of vertices not chosen yet but are connected to Lj

Stop when new layer is empty

Lj : all nodes at distance j from sLj : all nodes at

distance j from s

BFS TreeBFS naturally defines a tree rooted at s

Lj forms the jth “level” in the tree

u in Lj+1 is child of v in Lj from which it was “discovered”

11

22 33

44 55

66

77

88

11

22 33

L0

L1

44 55 77 88L2

66L3

Questions?

A theory workshop this weekend

http://www.cse.buffalo.edu/events/theory-III/

Proofs in the lectures

Mostly proof ideas from now on

Read the book for the formal proofs

Homeworks will still require formal proofs

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

Today’s agenda

If w is in R iff w is connected to s

Depth First Search

Computing all connected components

How is BFS related to this algo?

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

Questions?

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