hw3ans

hw3ans - 1. 22.1-2 Give an adjacency-list representation...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1. 22.1-2 Give an adjacency-list representation for a complete binary tree on 7 vertices. Give an equivalent adjacency-matrix representation. Assume that vertices are numbered from 1 to 7 as in a binary heap. 1 2 3 4 5 6 7 1 2 3 4 5 6 7 2 3 / 4 5 / 6 7 / / / / / Adjacency Matrix: 1 2 3 4 5 6 7 1 0 1 1 0 0 0 0 2 0 0 0 1 1 0 0 3 0 0 0 0 0 1 1 4 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 2. 22.1-5 The square of a directed graph G = (V, E) is the graph G 2 = (V, E 2 ) such that (u,w) E 2 if and only if for some v V, both (u,v) E and (v, w) E. That is, G 2 contains an edge between u and w whenever G contains a path with exactly two edges between u and w. Describe efficient algorithms for computing G 2 from G for both the adjacency-list and adjacency-matrix representations of G. Analyze the running times of your algorithms. G 2 for an adjacency matrix: - Computing G 2 may be done in V 3 time by matrix multiplication: for i = 1 to V for j = 1 to V { G 2 [i][j] = 0; for k = 1 to V if (g[i][k] == 1 && g[k][j] == 1) { G 2 [i][j] == 1; break; } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
G 2 for an adjacency list: Procedure G-Square (V[G], E[G]) V[G 2 ] V[G] for each u V[G] for each v Adj[u] for each w Adj[v] E[G 2 ] {(u, w)} E[G 2 ] Run time = O(V 3 ) 3. 22.2-1 Show the d and Π values that result from running breadth-first search on the directed graph of Figure 22.2(a), using vertex 3 as the source. 1 2 4 5 3 6 1/0/- 3/1/3 2/1/3 5/3/4 4/2/5 -/-/- 4. 22.2-3 What is the running time of BFS if its input graph is represented by an adjacency matrix and the algorithm is modified to handle this form of input? Each vertex can be explored once and its adjacent vertices must be determined too. This takes Θ (V 2 ) time. 5. Do a DFS on figure 22.6 (p.548). Classify each edge based on the DFS tree you determine. q t y x z s w v r u 1/16 2/7 3/6 4/5 10/11 9/12 8/15 13/14 18/19 17/20 T T T B T T B T T B T C C F 6. Find the strongly connected components in figure 22.6. From 5., the first DFS gives the list R U Q T Y X Z S U W (reverse order of turning black)
Background image of page 2
q t y x z s w v r u 5/10 15/20 17/18 16/19 12/13 11/14 7/8 6/9 3/4 1/2 C C C T B T C T B C C T T B Strongly connected components are {s, w, v}, {q, y, t}, {x, z}, {r}, {u} 7. 22.4-1 Show the ordering of vertices produced by TOPOLOGICAL-SORT when it is run on the dag of Figure 22.8, under the assumption of Exercise 22.3-2. m n o p q r s t u v w x y z 1/20 21/26 22/25 27/28 2/5 6/19 23/24 3/4 7/8 10/17 11/14 15/16 9/18 12/13 T T p n o s m r y v x w z u q t T T T T T T T T C T C C C C C F C C C 8. 22.5-1 How can the number of strongly connected components of a graph change if a new edge is added? The number of strongly connected components can be reduced.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
9. 22.5-3 Professor Deaver claims that the algorithm for strongly connected components can be simplified by using the original (instead of the transpose) graph in the second depth- first search and scanning the vertices in order of increasing finishing times. Is the professor correct? Consider 1 0 2 For this algorithm, the first DFS will give a list 1 2 0 for the second DFS. All vertices will be incorrectly reported to be in the same SCC.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

hw3ans - 1. 22.1-2 Give an adjacency-list representation...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online