Lecture 12 CSE 331 Sep 30, 2009. Announcements Final exam: Dec 16, 11:45am-2:45pm, NSC 210 HW 2...

Preview:

Citation preview

Lecture 12

CSE 331Sep 30, 2009

Announcements

Final exam: Dec 16, 11:45am-2:45pm, NSC 210

HW 2 solutions at the end of the lecture

Mid term: Oct 16, in class

Breath 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

Add non-tree edgesAdd non-

tree edges

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

Today’s agenda

Every edge is between consecutive layers

Depth First Search

A DFS run

11

22 33

44 55

66

77

88

11

22

44

55

66 33

88

77

Recommended