Fundamentals of Data Structures ... Java, Pascal, Turing or pseudo code. ... C Let
the adjacency matrix for the graph in Figure D be denoted as A. Complete, with ...
2008 November
Graph Questions
Page 1 of 3
Fundamentals of Data Structures Graphs Example test questions for the course These questions or similar questions have been used in tests in previous years. The course has been taught using various program languages, as a consequence the program text in these examples may be written in Java, Pascal, Turing or pseudo code. 1.
Given the graph in Figure D. 1
6 7
2
3
Figure D
8 4 A
5
Complete, including appropriate labels, the adjacency matrix A for the graph in Figure D.
B Suppose that the Floyd-Warshall algorithm is used for computing the transitive closure graph of the graph in Figure D. Complete, with appropriate labels, the adjacency matrix for the resulting transitive closure graph. C
Let the adjacency matrix for the graph in Figure D be denoted as A. Complete, with appropriate 3 labels, the matrix A . 2.
State the order in which the vertices of the graph in Figure E will be traversed when the edges incident on a vertex are traversed by the alphabetic order of the adjacent vertices, and each of the following traversal algorithms is used. Start at node A.
A
B
C
D
E
F
G
H
I
Place your answer within the indicated boxes. A
Depth-first traversal (DFT)
Figure E
2008 November
B 3.
Graph Questions
Page 2 of 3
Breadth-first traversal (BFT)
Given the following incidence matrix. Edges are labeled with characters. Vertices with integers.
a b c d e f h i
1
2
3
4
5
6
7
0 1 0 0 0 0 0 0
1 0 0 0 1 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 1
What is the corresponding adjacency matrix. Clearly label the resulting matrix. Without getting into excessive detail, explain, in English, how you arrived at the result.
4.
The following is Warshall’s algorithm with generalized sum and product operators, using an adjacency matrix. P ← A for j : 1 .. N do for k : 1 .. N do if P[j,k] satisfies COND then for p : 1 .. N do P[j,p] ← P[j,p] ⊕ ( P[j,k] ⊗ P[k,p] ) end for fi
2008 November
Graph Questions
Page 3 of 3
end for end for Explain what data must be in the adjacency matrix and what changes have to be made to the algorithm so that the maximum travel time path is computed between every pair of vertices. What is the Big O for the running time? 5. Assume that you are going to process directed graphs with the following structure: a. each vertex has a name; b. each edge has a distance associated with it; c. each edge has a name associated with it. A
Describe in detail, including structure definitions and diagrams, a multi-list representation for such graphs. As a function of the number of edges and vertices, how much space does the representation require?
B
Describe in detail, including structure definitions and diagrams, an adjacency list representation for such graphs. As a function of the number of edges and vertices, how much space does the representation require?
C
Assuming that a graph is represented using your description in part A, describe with pseudo-code an algorithm having as input the graph and the name of a vertex, and having as output the outdegree of the vertex (the number of edges leaving the vertex).
D
Assuming that a graph is represented using your description in part A, describe with pseudo-code an algorithm having as input the graph and the name of a vertex, and having as output the indegree of the vertex (the number of edges leaving the vertex).
What is the order of the time complexity of your algorithm with respect to the number of vertices and the number of edges? 6.
Given an adjacency matrix representation of a graph, describe with pseudo code an algorithm that finds a single path, if one exists, between any two different vertices.
7.
Given a multi-list representation of a graph, describe with pseudo code an algorithm which finds a single path, if one exists, between any two different vertices.
8.
Describe a multi-list data structure for storing a graph.