The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998

18.04.2013 Views

War Story: Dialing for Documents Next: Exercises Up: Graph Algorithms Previous: War Story: Nothing but Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE80.HTM (6 of 6) [19/1/2003 1:29:21]

Exercises Next: Implementation Challenges Up: Graph Algorithms Previous: War Story: Dialing for Exercises 1. Present correct and efficient algorithms to convert between the following graph data structures, for an undirected graph G with n vertices and m edges. You must give the time complexity of each algorithm. 1. Convert from an adjacency matrix to adjacency lists. 2. Convert from an adjacency list to an incidence matrix. An incidence matrix M has a row for each vertex and a column for each edge, such that M[i,j]=1 if vertex i is part of edge j, otherwise M[i,j] = 0. 3. Convert from an incidence matrix to adjacency lists. 2. Is the path between a pair of vertices in a minimum spanning tree necessarily a shortest path between the two vertices in the full graph? Give a proof or a counterexample. 3. Assume that all edges in the graph have distinct edge weights (i.e. no pair of edges have the same weight). Is the path between a pair of vertices in a minimum spanning tree necessarily a shortest path between the two vertices in the full graph? Give a proof or a counterexample. 4. Suppose G is a connected undirected graph. An edge e whose removal disconnects the graph is called a bridge. Must every bridge e be an edge in a depth-first search tree of G, or can e be a back edge? Give a proof or a counterexample. 5. (*) In breadth-first and depth-first search, an undiscovered node is marked discovered when it is first encountered, and marked completely-explored when it has been completely searched. At any given moment, several nodes might be simultaneously in the discovered state. (a) Describe a graph on n vertices and a particular starting vertex v such that during a breadth-first search starting from v, nodes are simultaneously in the discovered state. (b) Describe a graph on n vertices and a particular starting vertex v such that during a depth-first search starting from v, nodes are simultaneously in the discovered state. (c) Describe a graph on n vertices and a particular starting vertex v such that at some point during a depth-first search starting from v, nodes remain undiscovered, while nodes have been completely-explored. (Note, there may also be discovered nodes.) 6. Given the pre-order and in-order traversals of a binary tree, is it possible to reconstruct the tree? If file:///E|/BOOK/BOOK2/NODE81.HTM (1 of 3) [19/1/2003 1:29:23]

Exercises<br />

Next: Implementation Challenges Up: Graph <strong>Algorithm</strong>s Previous: War Story: Dialing for<br />

Exercises<br />

1. Present correct and efficient algorithms to convert between the following graph data structures,<br />

for an undirected graph G with n vertices and m edges. You must give the time complexity of<br />

each algorithm.<br />

1. Convert from an adjacency matrix to adjacency lists.<br />

2. Convert from an adjacency list to an incidence matrix. An incidence matrix M has a row<br />

for each vertex and a column for each edge, such that M[i,j]=1 if vertex i is part of edge j,<br />

otherwise M[i,j] = 0.<br />

3. Convert from an incidence matrix to adjacency lists.<br />

2. Is the path between a pair of vertices in a minimum spanning tree necessarily a shortest path<br />

between the two vertices in the full graph? Give a proof or a counterexample.<br />

3. Assume that all edges in the graph have distinct edge weights (i.e. no pair of edges have the same<br />

weight). Is the path between a pair of vertices in a minimum spanning tree necessarily a shortest<br />

path between the two vertices in the full graph? Give a proof or a counterexample.<br />

4. Suppose G is a connected undirected graph. An edge e whose removal disconnects the graph is<br />

called a bridge. Must every bridge e be an edge in a depth-first search tree of G, or can e be a<br />

back edge? Give a proof or a counterexample.<br />

5. (*) In breadth-first and depth-first search, an undiscovered node is marked discovered when it is<br />

first encountered, and marked completely-explored when it has been completely searched. At any<br />

given moment, several nodes might be simultaneously in the discovered state.<br />

(a) Describe a graph on n vertices and a particular starting vertex v such that during a breadth-first<br />

search starting from v, nodes are simultaneously in the discovered state.<br />

(b) Describe a graph on n vertices and a particular starting vertex v such that during a depth-first<br />

search starting from v, nodes are simultaneously in the discovered state.<br />

(c) Describe a graph on n vertices and a particular starting vertex v such that at some point during<br />

a depth-first search starting from v, nodes remain undiscovered, while nodes have been<br />

completely-explored. (Note, there may also be discovered nodes.)<br />

6. Given the pre-order and in-order traversals of a binary tree, is it possible to reconstruct the tree? If<br />

file:///E|/BOOK/BOOK2/NODE81.HTM (1 of 3) [19/1/2003 1:29:23]

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

Saved successfully!

Ooh no, something went wrong!