11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

400 Chap. 11 Graphs(a) IF an undirected graph is connected <strong>and</strong> has no simple cycles, THENthe graph has |V| − 1 edges.(b) IF an undirected graph has |V| − 1 edges <strong>and</strong> no cycles, THEN thegraph is connected.11.3 (a) Draw the adjacency m<strong>at</strong>rix represent<strong>at</strong>ion for the graph of Figure 11.26.(b) Draw the adjacency list represent<strong>at</strong>ion for the same graph.(c) If a pointer requires four bytes, a vertex label requires two bytes, <strong>and</strong>an edge weight requires two bytes, which represent<strong>at</strong>ion requires morespace for this graph?(d) If a pointer requires four bytes, a vertex label requires one byte, <strong>and</strong>an edge weight requires two bytes, which represent<strong>at</strong>ion requires morespace for this graph?11.4 Show the DFS tree for the graph of Figure 11.26, starting <strong>at</strong> Vertex 1.11.5 Write a pseudocode algorithm to cre<strong>at</strong>e a DFS tree for an undirected, connectedgraph starting <strong>at</strong> a specified vertex V.11.6 Show the BFS tree for the graph of Figure 11.26, starting <strong>at</strong> Vertex 1.11.7 Write a pseudocode algorithm to cre<strong>at</strong>e a BFS tree for an undirected, connectedgraph starting <strong>at</strong> a specified vertex V.11.8 The BFS topological sort algorithm can report the existence of a cycle if oneis encountered. Modify this algorithm to print the vertices possibly appearingin cycles (if there are any cycles).11.9 Explain why, in the worst case, Dijkstra’s algorithm is (asymptotically) asefficient as any algorithm for finding the shortest p<strong>at</strong>h from some vertex I toanother vertex J.11.10 Show the shortest p<strong>at</strong>hs gener<strong>at</strong>ed by running Dijkstra’s shortest-p<strong>at</strong>hs algorithmon the graph of Figure 11.26, beginning <strong>at</strong> Vertex 4. Show the Dvalues as each vertex is processed, as in Figure 11.19.11.11 Modify the algorithm for single-source shortest p<strong>at</strong>hs to actually store <strong>and</strong>return the shortest p<strong>at</strong>hs r<strong>at</strong>her than just compute the distances.11.12 The root of a DAG is a vertex R such th<strong>at</strong> every vertex of the DAG can bereached by a directed p<strong>at</strong>h from R. Write an algorithm th<strong>at</strong> takes a directedgraph as input <strong>and</strong> determines the root (if there is one) for the graph. Therunning time of your algorithm should be Θ(|V| + |E|).11.13 Write an algorithm to find the longest p<strong>at</strong>h in a DAG, where the length ofthe p<strong>at</strong>h is measured by the number of edges th<strong>at</strong> it contains. Wh<strong>at</strong> is theasymptotic complexity of your algorithm?11.14 Write an algorithm to determine whether a directed graph of |V| verticescontains a cycle. Your algorithm should run in Θ(|V| + |E|) time.11.15 Write an algorithm to determine whether an undirected graph of |V| verticescontains a cycle. Your algorithm should run in Θ(|V|) time.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!