lecture 17 cse 331 oct 8, 2010. hw 4 due today q1 and q2 in one pile q3 in another pile i will not...
Post on 21-Dec-2015
213 views
TRANSCRIPT
On Friday, Oct 15
hours-a-thon
Atri: 2:00-3:30 (Bell 123)
Jeff: 3:30-5:00 (Commons 9)Alex: 5:00-6:30 (Bell 224)
DFS(u)
u is explored
For every unexploredneighbor v of u
DFS(v)
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
Graph representations
Adjacency matrix
0
1
1
1
0
0
1
0
0
Adjacency List
(u,v) in E?O(1) O(n) [ O(nv) ]
All neighbors of u?O(n) O(nu)
Space?O(n2) O(m+n)
Better for sparse graphs and traversals
Better for sparse graphs and traversals