Lecture 12 CSE 331 Sep 30, 2009

advertisement
Lecture 12
CSE 331
Sep 30, 2009
Announcements
Final exam: Dec 16, 11:45am-2:45pm, NSC 210
Mid term: Oct 16, in class
HW 2 solutions at the end of the lecture
Breath First Search (BFS)
Is s connected to t?
Build layers of vertices connected to s
L0 = {s}
Lj : all nodes at
distance j from 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
BFS Tree
BFS 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”
1
2
7
Add nontree edges
L0
1
2
3
L1
3
8
4
5
6
4
5
6
7
8
L2
L3
Connected Component
Connected 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
1
1
7
2
2
3
8
4
4
5
5
6
6
3
8
7
Download