Graphs
Graphs
1. (a) How many binary relations are there on a set A with n elements?
(b) How many one-to-one functions are there from a set A with n elements onto itself?
(c) Show that the number of odd degree vertex in a finite graph is even.
(d) Specify an adjacency-lists representation of the undirected graph.
3. Write the adjacency matrix representation of the graph given in fig below:
P1
P5 P2
P4 P3
4. In the graph shown below, the depth-first spanning tree edges are marked with ‘T’. Identify the forward, backward and cross edges.
5. The maximum number of possible edges in an undirected graph with n vertices and k components is ___________________.
6. Show that all vertices in an undirected finite graph cannot have distinct degrees, if the graph has at least two vertices
8. Consider a simple connected graph G with n vertices and n edges (n>2). Then which of the following statements are true
5
Which one of the following is NOT the sequence of edges added to the minimum spanning tree using Kruskal’s algorithm?
10. Which one of the following is TRUE for any simple connected undirected graph with more that 2 vertices?
(A) No two vertices have the same degree.
(B) At least two vertices have the same degree.
(C) At least three vertices have the same degree.
(D) All vertices have the same degree.
11. Consider the following sequences of nodes for the undirected graph given below.
I. a b e f d g c
II. a b e f c g d
III. a d g e b c f
IV. a d b c g e f
A Depth First Search (DFS) is started at node a. The nodes are listed in the order they are first visited. Which all of the above is (are) possible
output(s)?
(A) I and III only
(B) II and III only
(C) II, III and IV only
(D) I, II and III only
12. For the undirected, weighted graph given below, which of the following sequences of edges represents a correct execution of Prims algorithm to
construct a Minimum Spanning Tree?
(D) (a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
(E) (c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
(F) (d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
(G) (h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
6
13. G is a simple undirected graph. Some vertices of G are of odd degree. Add a node v to G and make it adjacent to each odd degree vertex
of G . The resultant graph is sure to be
(A) regular
(B) complete
(C) Hamiltonian
(D) Euler
14. What is the chromatic number of the following graph?
(A) 2
(B) 3
(C) 4
(D) 5
15.
b -3 e
2 2
1 1 1
a c -5 h f
3 3
2 2
d 2 g
Dijkstras single source shortest path algorithm when run from vertex a in the above graph, computes the correct shortest path distance to
(A) only vertex a
(B) only vertices a, e, f , g , h
(C) only vertices a, b, c, d
(D) all the vertices
17. Which of the following statements is true for every planar graph on n vertices?
(A) The graph is connected
(B) The graph is Eulerian
(C) The graph has a vertex‐cover of size at most 3n/4
(D) The graph has an independent set of size at least n/3
18. The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the
following graph is
M N O
R Q P
(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR
7
19. The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time
complexity
(A) Θ (n)
(B) Θ (m)
(C) Θ (m + n)
(D) Θ (mn)
20. What is the largest m such that every simple connected graph with n vertices and n edges contains at least m different spanning trees?
21. Consider the DAG with V = {1, 2, 3, 4, 5, 6}, shown below.
Which one the following is NOT a topological ordering?
(A) 1 2 3 4 5 6 (B) 1 3 2 4 5 6
(C) 1 3 2 4 6 5 (D) 3 2 4 1 6 5
22. Let G be the non‐planar graph with the minimum possible number of edges. Then G has
(A) 9 edges and 5 vertices
(B) 9 edges and 6 vertices
(C) 10 edges and 5 vertices
(D) 10 edges and 6 vertices
23. Consider the depth first search of an undirected graph with 3 vertices P, Q and R. Let discovery time d(u) represent the time instant when the
vertex u is first visited, and finis time f(u) represent the time instant when the vertex u is last visited. Given that
d(P) = 5 units f(P) = 12 units
d(Q) = 6 units f(Q) = 10 units
d(R) = 14 units f(R) = 18 units
Which of the following statements is TRUE about the graph?
(A) There is only one connected component
(B) There are connected components, and P and R are connected
(C) There are connected components, and Q and R are connected
(D) There are connected components, and P and Q are connected
24. Which of the following is the correct decomposition of the directed graph given below into its strongly connected components?
(A) {P, Q, R, S}, {T}, {U}, {V} (B) {P, Q, R, S, T, V}, {U}
(C) {P, Q, S, T, V}, {R}, {U} (D) {P, Q, R, S, T, U, V}
8
25. Consider the undirected graph G defined as follows. The vertices of G are bit strings of length n. we have an edge between vertex u and vertex v if
and only if u and v differ in exactly one bit position (in other words, v can be obtained from u by flipping a single bit). The ratio of the chromatic
number of G to the diameter of G is
26. If all the edge weights of an undirected graph are positive, then any subset of edges that connects all the vertices and has minimum total weight is
a
27. In a binary tree, the number of internal nodes of degree 1 is 5, and the number of internal nodes of degree 2 is 10. The number of leaf nodes in the
binary tree is
28. The 2n vertices of a graph G corresponds to all subsets of size n, for n ≥ 6. Two vertices of G are adjacent if and only if the corresponding sets
intersect in exactly two elements.
The number of connected components in G is
2n
(A) 2 (B) n +2 (C) 2n/2 (D)
n
The maximum degree of a vertex in G is
⎛ n / 2⎞ n / 2
(A) ⎜⎜ ⎟⎟2 (B) 2n ‐ 2 (C) 2n‐3 x 3 (D) 2n‐1
⎝ 2 ⎠
The number of vertices of degree zero in G is
29. Let T be a depth first search tree in an undirected graph G. Vertices u and v are leaves of this tree T. The degrees of both u and v in G are at least 2.
Which one of the following statements is true?
(A) There must exist a vertex w adjacent to both u and v in G
(B) There must exist a vertex w whose removal disconnects u and v in G
(C) There must exist a cycle in G containing u and v
(D) There must exist a cycle in G containing u and v and all its neighbours in G
30. Consider the following graph
Which one of the following cannot be the sequence of edges added, in that order, to a minimum spanning tree using Kruskals algorithm?
(A) (a-b), (d-f), (b-f), (d-c), (d-e) (B) (a-b), (d-f), (d-c), (b-f), (d-e)
9
(C) (d-f), (a-b), (d-c), (b-f), (d-e) (D) (d-f), (a-b), (b-f), (d-e), (d-c)
31. To implement Dijkstras shortest path algorithm on undirected graphs so that it runs in linear time, the data structure to be used is
⎛n⎞
(A) n 1 (B) 2n 2 (C) ⎜⎜ ⎟⎟ (D) n2
⎝ 2⎠
33. Let G be a directed graph whose vertex set is the set of number from 1 to 100. There is an edge from a vertex i to a vertex j iff either j = i + 1 or j =
3i. the minimum number of edges in a path in G from vertex 1 to 100 is
34. Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is minimum weight spanning tree in G
containing edge e. which of the following statements is always true?
(A) There exists a cutest in G having all edges of maximum weight.
(B) There exists a cycle in G having all edges of maximum weight.
(C) Edge e can be contained in a cycle.
(D) All edges in G have same weight.
1: Bellman‐Ford algorithm A: O(m log n)
2: Kruskals algorithm B: O(n3)
3: Floyd‐Warshall algorithm C: O(nm)
4: Topological sorting D: O(n + m)
(A) 1→ C, 2→ A, 3→ B, 4→ D
(B) 1→ B, 2→ D, 3→ C, 4→ A
(C) 1→ C, 2→ D, 3→ A, 4→ B
(D) 1→ B, 2→ A, 3→ C, 4→ D
36. In depth first traversal of a graph G with n vertices, k edges are marked as tree edges. The number of connected components in G is
37. Statement for Linked Answer Questions 82a & 82b:
Let s and t be two vertices in a undirected graph G = (V, E) having distinct positive edge weights. Let [X, Y] be partition of V such that s Є X and t Є
Y. Consider the edge e having the minimum weight amongst all those edges that have one vertex in X and one vertex in Y.
(a) The edge e must definitely belong to:
(A) The minimum weighted spanning tree of G
(B) The weighted shortest path from s to t
(C) Each path from s to t
(D) The weighted longest path from s to t
10
(b) Let the weight of an edge e denote the congestion on that edge. the congestion on a path is defined to be the maximum of the
congestions on the edges of the path. We wish to find the path from s to t having minimum congestion. Which of the following paths is
always such a path of minimum congestion?
(A) A path from s to t in the minimum weighted spanning tree
(B) A weighted shortest path from s to t
(C) An Euler walk from s to t
(D) A Hamiltonian path from s to t
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29
Which one of the following sequences of keys can be the result of an inorder traversal of tree T?
(A) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
(B) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
(C) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(D) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29
39. Let G be a simple connected graph with 13 vertices and 19 edges. Then, the number of faces in the planar embedding of the graph is:
(A) 6
(B) 8
(C) 9
(D) 13
40. An undirected graph G has n nodes. its adjacency matrix is given by an n × n square matrix whose (i) diagonal elements are 0s and (ii) non‐
diagonal elements are 1s. Which one of the following is TRUE?
(A) Graph G has no minimum spanning tree (MST)
(B) Graph G has a unique MST of cost n‐1
(C) Graph G has multiple distinct MSTs, each of cost n‐1
(D) Graph G has multiple minimum spanning trees of different costs.
41. Consider the undirected graph below.
Using Prims algorithm to construct a minimum spanning tree starting with node A, which one of the following sequences of edges represents a
possible order in which the edges would be added to construct the minimum spanning tree?
(A) (E, G), (C, F), (F, G), (A, D), (A, B), (A, C)
(B) (A, D), (A, B), (A, C), (C, F), (G, E), (F, G)
(C) (A, B), (A, D), (D, F), (F, G), (G, E), (F, C)
(D) (A, D), (A, B), (D, F), (F, C), (F, G), (G, E)
42. What is the number of vertices in an undirected connected graph with 27 edges, 6 vertices of degree 2, 3 vertices of degree 4 and remaining of
degree 3?
(A) 10
(B) 11
(C) 18
(D) 19
43. What is the number of edges in an acyclic undirected graph with n vertices?
(A) n 1
11
(B) n
(C) n + 1
(D) 2n 2
44. Let G1 = (V, E1) and G2 = (V, E2) be connected graphs on the same vertex set V with more than two vertices. If G 1 � G2 = (V, E1 � E2) is not a
connected graph, then the graph G1 U G2 = (V, E1 U E2)
(A) Cannot have a cut vertex
(B) Must have a cycle
(C) Must have a cut‐edge (bridge)
(D) Has chromatic number strictly greater than those of G1 and G2
45. How many graphs on n labeled vertices exist which have at least (n2 3n)/2) edges?
( n ^ 2−n ) / 2
(A) C ( n ^ 2 −3 n ) / 2
( n ^ 2 −3 n ) / 2
(B) ∑k =0
( n ^ 2−n )
Ck
( n ^ 2− n ) / 2
(C) Cn
n
(D) ∑
k =0
( n ^ 2− n ) / 2
Ck
46. The minimum number of colours required to colour the following graph, such that no two adjacent vertices are assigned the same colour, is
(A) 2
(B) 3
(C) 4
(D) 5
47. Suppose we run Dijkstras single source shortest path algorithm on the following edge‐weighted directed graph with vertex P as the source.
In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?
(A) P, Q, R, S, T, U
(B) P, Q, R, U, S, T
(C) P, Q, R, U, T, S
(D) P, Q, T, R, U, S
n3 can be expressed as:
(A) n1 + n2 − 1
(B) n1 − 2
⎡ n + n2 ⎤
(C) ⎢ 1
⎢ 2 ⎥⎥
(D) n2 − 1
Starting with the above tree, while there remains a node v of degree two in the tree, add an edge between the two neighbours of v and then
12
remove v from the tree. How many edges will remain at the end of the process?
(A) 2* n1 − 3
(B) n2 + 2* n1 − 2
(C) n3 − n2
(D) n2 + n1 − 2
49. Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have
encountered them in the search?
(A) II and III only
(B) I and III only
(C) III and IV only
(D) III only
Which of the following statements is TRUE?
(A) I, II and IV are inorder sequences of three different BSTs
(B) I is a preorder sequence of some BST with 439 as the root
(C) II is an inorder sequence of some BST where 121 is the root and 52 is a leaf
(D) IV is a postorder sequence of some BST with 149 as the root.
How may distinct BSTs can be constructed with 3 distinct keys?
(A) 4
(B) 5
(C) 6
(D) 9
50. In an unweighted, undirected connect graph, the shortest path from a node S to every node is computed most efficiently, in terms of time
complexity, by
(A) Dijkstras algorithm starting from S.
(B) Warshalls algorithm.
(C) Performing a DFS starting from S.
(D) Performing a BFS starting from S.
51. The following algorithm (written in pseudo‐Pascal) works on a undirected graph G
Program Explore (G)
procedure Visit (u)
begin
if Adj (u) is not empty
{ comment : Adj (u) is the list of edges incident to u}
then
begin
select an edge from Adj (u);
Let an edge e = (u, v);
remove e from Adj (u) and Adj (v);
Visit (v);
end
else
mark u as a finished vertex and remove u from LIST;
{Comment : LIST is the set of vertices in the graph}
13
end;
begin
while LIST is not empty
do
begin
Let v ε LIST;
Visit (v);
end
end
NOTE: Initially Adj (u) is the list of all edges incident to u and LIST is the set of all vertices in the graph. They are globally accessible.
What kinds of sub graphs are obtained when this algorithm traverses the graphs G1 and G2 shown in Fig. 6 and Fig. 7, respectively?
Fig. 6 Fig. 7
(a) What is the commonly known traversal of graphs that can be obtained from the sub graphs generated by Program Explore?
(b) Show that the time complexity of the procedure is O (v + e) for a graph with v vertices and e edges, given that each vertex can be accessed
and removed from LIST in const time. Also show that all edges of the graph are traversed.
52. The maximum number of possible edges in an undirected graph with n vertices and k components is ___________________.
53. Kruskals algorithm for finding a minimum spanning tree of a weighted graph G with n vertices and m edges has the time‐complexity of:
A. (n2)
B. (m n)
C. (m + n)
D. (m log n)
E. (m2)
54. Show that all vertices in an undirected finite graph cannot have distinct degrees, if the graph has at least two vertices
56. Maximum number of edges in a planner graph with n vertices is __________________.
57. A non‐planer graph with minimum number of vertices has
(A) 9 edges, 6 vertices
(B) 6 edges, 4 vertices
(C) 10 edges, 5 vertices
(D) 9 edges, 5 vertices
58. How many edges are there in a forest with p components having n vertices in all?
59. An independent set in a graph is a subset of vertices such that no two vertices in the subset are connected by an edge. An incomplete scheme for
greedy algorithm to find a maximum independent set in a tree is given below:
V: = Set of all vertices in a tree;
I: = φ do
14
begin
select a vertex u Є V such that
________________ ;
V: = V {u};
If u is such that
______________ then I: = I U{u}
end;
Output (I);
Complete the algorithm by specifying the property of vertex u in each case. (4)
What is the time complexity of the algorithm?
60. Consider a simple connected graph G with n vertices and n edges (n>2). Then which of the following statements are true
(f) G has no cycles
(g) the graph obtained by removing any edges from G is not consider connected
(h) G has at least one cycle
(i) the graph obtained by removing any two edges from G is not consider connected
(j) none of the above.
61. The number of distinct simple graphs with upto three nodes is
(A) 15
(B) 10
(C) 7
(D) 9
62. The number of edges in a regular graph of degree d and n vertices are .
63. The minimum number of edges in a connected cyclic graph on n vertices is
(A) n ‐ 1
(B) n
(C) n + 1
(D) None of the above
64. How many minimum spanning trees does the following graph have? Draw them (weights are assigned to the edges).
66. A complete undirected, weighted graph G is given on the vertex set {0, 1, ..,n‐1} for any fixed n. Draw the minimum spanning tree of G if
(a) The weight of the edge (u, v) is |u v|
(b) The weight of the edge (u, v) is u + v
67. Let G be the directed, weighted graph shown below in Fig. 17
15
Fig. 17
We are interested in the shortest paths from A.
68. Which of the following algorithm design techniques is used in finding all pairs of shortest distances in a graph?
(a) Dynamic programming (b) Backtracking
(c) Greedy (d) Divide and Conquer
69. Consider a graph whose vertices are points in the plane with integer co‐ordinates (x,y) such that 1 ≤ x ≤ n and 1 ≤ y ≤ n, where n ≥ 2 is an integer.
Two vertices (x1, y1) and (x2, y2) are adjacent iff |x1 x2| ≤ 1v |y1 y2| ≤ 1. The weight of na edge {(x1, y1), (x2, y2)} is
(x1 − x2 )2 + ( y1 − y 2 )2 .
What is the weight of a maximum weight spanning tree in this graph? Write only the answer without any explanations.
(A) 8 (B) 4 (C) 12 (D) 25
71. The number of articulation points of the following graph is:
(A) 0
(B) 1
(C) 2
(D) 3
Which of the following is false?
(A) Every minimum spanning tree of G must contain emin
(B) If emax is an minimum spanning tree, then its removal must disconnect G
(C) No minimum spanning tree contains emax
16
(D) G has a unique minimum spanning tree
73. Let G be an undirected graph. Consider a depth first traversal G, and let T be the resulting depth first search tree. Let u be a vertex in G and v be
the first new (unvisited) vertex visited after visiting u in the traversal. Which of the following is always true?
(A) {u,v} must be an edge in G, and u is descendent of v in T
(B) {u,v} must be an edge in G, and v is descendent of u in T
(C) If {u,v} is not an edge in G then u is leaf in T
(D) If {u,v} is not an edge in G then u and v must have the same parent in T
(a) Lists the edges of a minimum spanning tree of the graph. (2)
(b) How many distinct minimum spanning tree does this graph have?
(c) Is the minimum among the edge weights of a minimum spanning tree unique over all possible minimum spanning trees of a graph? (1)
(d) Is the maximum among the edge weights of a minimum spanning tree unique over all possible minimum spanning trees of a graph?
76. The minimum number of colors required to color the vertices of a cycle with n nodes in such a way that no two adjacent nodes have the same
color is:
A. 2
B. 3
C. 4
D. n 2 ⎣n/2⎦ + 2
77. The Maximum number of edges in a n node undirected graph without self loops is
A. n2
B. n(n 1)/2
C. n ‐1
D. (n+1)(n)/2
78. The number of distinct simple graphs with upto three nodes is
(E) 15
(F) 10
(G) 7
(H) 9
79. Fill in the blanks in the following template of an algorithm to compute all pairs shortest path lengths in a directed graph G with n*n adjacency
matrix A. A[i, j] equals 1 if there is an edge in G from i to j, and 0 otherwise. Your aim in filling in the blanks
INITIALIZATION: For I = 1 n
{For j = 1 n
{If A[i,j] = 0 then P[i, j] = ________ else P[i,j] = _______;}
}
ALGORITHM: For i = 1 ... n
{ For j = 1 n
17
{ For k = 1
n
{P[ _, _ ] = min{ ____________};}
}
}
80. Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from G, the number of components in the resultant graph
must necessarily lie between
(A) k and n
(B) k 1 and k + 1
(C) k 1 and n 1
(D) k + 1 and n k
81. Consider the following graph
Among the following sequences
I a b e g h f
II a b f e h g
III a b f h g e
IV a f g h b e
Which are depth first traversals of the above graph?
(A) I, II and IV only
(B) I and IV only
(C) II, III and IV only
(D) I, III and IV only
82. How many perfect matching are there in a complete graph of 6 vertices?
(A) 15
(B) 24
(C) 24
(D) 60
83. Let G = (V, E) be an undirected graph with a subgraph G1 = (V1, E1). Weights are assigned to edges of G as follows.
A single‐source shortest path algorithm is executed on the weighted graph (V, E, what) with an arbitrary vertex v1 of V1 as the source.
Which of the following can always be inferred from the path costs computed?
(A) The number of edges in the shortest paths from v1 to all vertices of G
(B) G1 is connected.
(C) V1 forms a clique in G
(D) G1 is a tree
18
84. What is the weight of a minimum spanning tree of the following graph?
(A) 29
(B) 31
(C) 38
(D) 41
19