cse101_10_26_11

cse101_10_26_11 - connected components. 3. Previsit and...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Depth-first search Global cc = 1 Procedure explore(G,u) Visited[u] = true Previsit() For all(u, w) in E: If not visited(w) Explore(g, w) Postvisit(u) Procedure dfs(G) For all u in V: Visited[u] = false For all u in V If not visited[u] Explore(G, u) Cc++ 1. Running time analysis a. Explore(G, u) is called exactly once for each node u. b. Amount of work done per node = O(1) c. For any edge {u, w}, the edge is seen exactly twice, once when exploring u, and once when exploring w. Each time O(1) work. d. Total work = O(abs(v) + abs(e)) 2. Decomposing an undirected graph into connected components a. Proceure previsit(u) Ccnum[u] = cc Yields an array ccnum[i] in which each node is assigned the number of the connected components it lies in. b. Therefore, linear time algorithm for decomposing an undirected graph into its
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: connected components. 3. Previsit and postvisit numbers. a. During DFS, for each node u, record: a.i. Time of initial discovery: (pre[u]) a.ii. Time of final departure: post[u] b. A (1) B (2) E (3 pre) (4 post) F (5 pre 6 post) B (7 post) A (8 post) C (9 pre) D (10, 11) g(12, 13) C(14) c. Procedure previsit(u) Pre[u] = clock++ Procedure postvisit(u) Post[u] = clock++; Property: either they are nested within each other or they are completely disjoint. d. For any nodes u and w, the intervals pre[u], post[u] and pre[w], post[w] are either disjoint [ ] [ ]or nested [ [ ] ] 4. DFS on directed graphs a. Same idea, but is directed...
View Full Document

Ask a homework question - tutors are online