Graphs
Question 1 
I only  
II only  
Both I and II  
Neither I nor II 
Question 1 Explanation:
I. Undirected graph do not have cross edges in DFS. But can have cross edges in directed graph. Hence True.
II. Just draw a triangle ABC. Source is A. Vertex B and C are at same level at distance 1. There is an edge between B and C too. So here i  j = 1  1 = 0.
Hence, False.
II. Just draw a triangle ABC. Source is A. Vertex B and C are at same level at distance 1. There is an edge between B and C too. So here i  j = 1  1 = 0.
Hence, False.
Question 2 
P only  
Q only  
Neither P nor Q  
Both P and Q 
Question 2 Explanation:
Given undirected weighted graph with distinct positive edges. Every edge weight is increased by the same value say,
P: Minimum Spanning Tree will not change ABC in both the cases.
Q: Shortest path will change because in 1st figure the path from A to C calculated as ABC but in fig.2, it is AC (Direct path).
P: Minimum Spanning Tree will not change ABC in both the cases.
Q: Shortest path will change because in 1st figure the path from A to C calculated as ABC but in fig.2, it is AC (Direct path).
Question 3 
12  
13  
14  
15 
Question 3 Explanation:
Let vertices be A, B, C and D.
x directly connects C to D.
The shortest path (excluding x) from C to D is of weight 12 (CBAD).
x directly connects C to D.
The shortest path (excluding x) from C to D is of weight 12 (CBAD).
Question 4 
In an adjacency list representation of an undirected simple graph G = (V,E), each edge (u,v) has two adjacency list entries: [v] in the adjacency list of u, and [u] in the adjacency list of v. These are called twins of each other. A twin pointer is a pointer from an adjacency list entry to its twin. If E= m and V = n, and the memory size is not a constraint, what is the time complexity of the most efﬁcient algorithm to set the twin pointer in each entry in each adjacency list?
Θ(n^{2})  
Θ(n+m)  
Θ(m^{2})  
Θ(n^{4}) 
Question 4 Explanation:
Applying BFS on Undirected graph give you twin pointer. Visit every vertex levelwise for every vertex fill adjacent vertex in the adjacency list. BFS take O(m+n) time.
Note: Twin Pointers can be setup by keeping track of parent node in BFS or DFS of graph.
Note: Twin Pointers can be setup by keeping track of parent node in BFS or DFS of graph.
Question 5 
Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time of Depth First Search on G, when G is represented as an adjacency matrix?
θ(n)  
θ(n+m)  
θ(n^{2} )  
θ(m^{2} ) 
Question 5 Explanation:
DFS visits each vertex once and as it visits each vertex, we need to find all of its neighbours to figure out where to search next. Finding all its neighbours in an adjacency matrix requires O(V ) time, so overall the running time will be O(V^{2}).
Question 6 
The graph does not have any topological ordering.  
Both PQRS and SRQP are topological.  
Both PSRQ and SPRQ are topological orderings.  
PSRQ is the only topological ordering. 
Question 6 Explanation:
There are no cycles in the graph, so topological orderings do exist.
We can consider P & S as starting vertex, followed by R & Q.
Hence, PSRQ & SPRQ are the topological orderings.
Question 7 
Consider the tree arcs of a BFS traversal from a source node W in an unweighted, connected, undirected graph. The tree T formed by the tree arcs is a data structure for computing
the shortest path between every pair of vertices.  
the shortest path from W to every vertex in the graph.  
the shortest paths from W to only those nodes that are leaves of T.  
the longest path in the graph. 
Question 7 Explanation:
One of the application of BFS algorithm is to find the shortest path between nodes u and v.
But in the given question the BFS algorithm starts from the source vertex w and we can find the shortest path from W to every vertex of the graph.
But in the given question the BFS algorithm starts from the source vertex w and we can find the shortest path from W to every vertex of the graph.
Question 8 
19  
20  
21  
22 
Question 8 Explanation:
Note: We should not consider backtrack edges, it reduces recursion depth in stack.
So the maximum possible recursive depth will be 19.
Question 9 
7  
8  
9  
10 
Question 9 Explanation:
The possible minimum path is,
B → A, A → E, E → C.
B → A, A → E, E → C.
Question 10 
The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time complexity
θ(n)  
θ(m)  
θ(m+n)  
θ(mn) 
Question 10 Explanation:
To find the number of connected components using either BFS or DFS time complexity is θ(m+n).
Suppose if we are using Adjacency matrix means it takes θ(n^{2}).
Suppose if we are using Adjacency matrix means it takes θ(n^{2}).
Question 11 
MNOPQR
 
NQMPOR
 
QMNPRO
 
QMNPOR 
Question 11 Explanation:
Check with the options:
Option A: MNOPQR
→ If queue starts with M then neighbour nodes are {N,Q,R}.
→If Q starts with M then string is not matching with neighbour nodes.
So, option A is wrong.
Option B: NQMPOR
→ Neighbours of N is ⇒ {Q,M,O}
String is not matched with neighbours.
So, option B is wrong.
Question 12 
G is a graph on n vertices and 2n – 2 edges. The edges of G can be partitioned into two edgedisjoint spanning trees. Which of the following is NOT true for G?
For every subset of k vertices, the induced subgraph has at most 2k–2 edges  
The minimum cut in G has at least two edges
 
There are two edgedisjoint paths between every pair to vertices
 
There are two vertexdisjoint paths between every pair of vertices 
Question 12 Explanation:
→ In Spanning tree n nodes require n1 edges. The above question they mentioned 2 disjoint spanning trees. So, it requires n1 + n1 =2n2 edges. Except option D everything is correct.
> Option A: True: Subgraph with k vertices here is no chance to get more than 2k−2 edges. Subgraph with n−k vertices, definitely less than 2n−2k edges.
> Option B: True: Take any subgraph SG with k vertices. The remaining subgraph will have n−k vertices. Between these two subgraphs there should be at least 2 edges because we are taken 2 spanning trees in SG.
> Option C: True: A spanning tree covers all the vertices. So, 2 edgedisjoint spanning trees in G means, between every pair of vertices in G we have two edgedisjoint paths (length of paths may vary).
> Option A: True: Subgraph with k vertices here is no chance to get more than 2k−2 edges. Subgraph with n−k vertices, definitely less than 2n−2k edges.
> Option B: True: Take any subgraph SG with k vertices. The remaining subgraph will have n−k vertices. Between these two subgraphs there should be at least 2 edges because we are taken 2 spanning trees in SG.
> Option C: True: A spanning tree covers all the vertices. So, 2 edgedisjoint spanning trees in G means, between every pair of vertices in G we have two edgedisjoint paths (length of paths may vary).
Question 13 
I and III only  
II and III only  
II, III and IV only  
I, II and III only

Question 13 Explanation:
I) After visiting 'f', 'c' or 'g' should be visited next. So, the traversal is incorrect.
IV) After visiting 'c', 'e' or 'f' should be visited next. So, the traversal is incorrect.
IV) After visiting 'c', 'e' or 'f' should be visited next. So, the traversal is incorrect.
Question 14 
1 2 3 4 5 6  
1 3 2 4 5 6  
1 3 2 4 6 5  
3 2 4 1 6 5

Question 14 Explanation:
The process to find topological order is,
(i) Go with vertex with indegree 0.
(ii) Then remove that vertex and also remove the edges going from it.
(iii) Repeat again from (i) till every vertex is completed.
Now we can see that in option (D), '3' is given first which is not possible because indegree of vertex '3' is not zero.
Hence option (D) is not topological ordering.
(i) Go with vertex with indegree 0.
(ii) Then remove that vertex and also remove the edges going from it.
(iii) Repeat again from (i) till every vertex is completed.
Now we can see that in option (D), '3' is given first which is not possible because indegree of vertex '3' is not zero.
Hence option (D) is not topological ordering.
Question 15 
A depthfirst search is performed on a directed acyclic graph. Let d[u] denote the time at which vertex u is visited for the first time and f[u] the time at which the dfs call to the vertex u terminates. Which of the following statements is always true for all edges (u, v) in the graph ?
d[u] < d[v]  
d[u] < f[v]  
f[u] < f[v]  
f[u] > f[v] 
Question 15 Explanation:
Option A:
d[u]
d[u]
f[u]
Question 16 
Let T be a depth first search tree in an undirected graph G. Vertices u and n 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?
There must exist a vertex w adjacent to both u and v in G
 
There must exist a vertex w whose removal disconnects u and v in G  
There must exist a cycle in G containing u and v
 
There must exist a cycle in G containing u and all its neighbours in G 
Question 16 Explanation:
Very difficult assume a graphs here. So, As per the GATE key they given Option D is correct answer.
Question 17 
{P, Q, R, S}, {T}, {U}, {V}  
{P, Q, R, S, T, V}, {U}  
{P, Q, S, T, V}, {R}, {U}  
{P, Q, R, S, T, U, V} 
Question 17 Explanation:
In a strongly connected component every two vertices must be reachable from one to other and itis maximal component.
From given graph {P, Q, R, S, T, V} and {U} are strongly connected components.
From given graph {P, Q, R, S, T, V} and {U} are strongly connected components.
Question 18 
There is only one connected component  
There are two connected components, and P and R are connected  
There are two connected components, and Q and R are connected  
There are two connected components, and P and Q are connected 
Question 18 Explanation:
Since, d(q) = d(p) + 1 and f(q) < f(p) which means p and q are connected and r is separate, so (D) is the answer.
Question 19 
An undirected graph C has n nodes. Its adjacency matrix is given by an n × n square matrix whose (i) diagonal elements are 0's and (ii) nondiagonal elements are l's. Which one of the following is TRUE?
Graph G has no minimum spanning tree (MST)
 
Graph G has a unique MST of cost n1
 
Graph G has multiple distinct MSTs, each of cost n1
 
Graph G has multiple spanning trees of different costs

Question 19 Explanation:
From given data, we can say that the given graph is complete graph with all edge weights 1. Hence weight of MST is n1.
Since the weights of every edge is 1 so there are different MST's are possible with same cost, i.e., (n1).
Since the weights of every edge is 1 so there are different MST's are possible with same cost, i.e., (n1).
Question 20 
the minimum weighted spanning tree of G
 
the weighted shortest path from s to t
 
each path from s to t
 
the weighted longest path from s to t

Question 20 Explanation:
Since every edge has distinct edge weights. So, the edge with minimum weight will definitely be present in MST.
Question 21 
a path from s to t in the minimum weighted spanning tree
 
a weighted shortest path from s to t
 
an Euler walk from s to t
 
a Hamiltonian path from s to t

Question 21 Explanation:
Let us first understand what is minimum congestion actually.
Minimum congestion is the edge with maximum weight among all other edges included in the path.
Now suppose shortest path from A→B is 6, but in MST, we have A→C→B(A→C=4, C→B=3), then along the path in MST, we have minimum congestion i.e., 4.
Minimum congestion is the edge with maximum weight among all other edges included in the path.
Now suppose shortest path from A→B is 6, but in MST, we have A→C→B(A→C=4, C→B=3), then along the path in MST, we have minimum congestion i.e., 4.
Question 22 
E_{1} : A[i][j] and E_{2} : i = j;  
E_{1} : !A[i][j] and E_{2} : i = j + 1;  
E_{1}: !A[i][j] and E_{2} : i = j;  
E_{1} : A[i][j] and E_{2} : i = j + 1;

Question 22 Explanation:
If there is a sink in the graph, the adjacency matrix will contain all 1's (except diagonal) in one column and all 0's (except diagonal) in the corresponding row of that vertex. The given algorithm is a smart way of doing this as it finds the sink in O(n) time complexity.
The first part of the code, is finding if there is any vertex which doesn't have any outgoing edge to any vertex coming after it in adjacency matrix. The smart part of the code is E_{2}, which makes rows slip when there is no edge from i to it, making it impossible for them to form a sink. This is done through
E_{1}: A[i][j]
and
E_{2}: i = j
E_{1} makes sure that there is no edge from i to j and i is a potential sink till A[i][j] becomes 1. If A[i][j] becomes 1, i can no longer be a sink. Similarly, all previous j can also not be a sink. Now, the next potential candidate for sink is j. So, in E_{2}, we must make i = j.
So, answer is (C).
The first part of the code, is finding if there is any vertex which doesn't have any outgoing edge to any vertex coming after it in adjacency matrix. The smart part of the code is E_{2}, which makes rows slip when there is no edge from i to it, making it impossible for them to form a sink. This is done through
E_{1}: A[i][j]
and
E_{2}: i = j
E_{1} makes sure that there is no edge from i to j and i is a potential sink till A[i][j] becomes 1. If A[i][j] becomes 1, i can no longer be a sink. Similarly, all previous j can also not be a sink. Now, the next potential candidate for sink is j. So, in E_{2}, we must make i = j.
So, answer is (C).
Question 23 
(A[i][j] && !A[j][i])  
(!A[i][j] && A[j][i])  
(!A[i][j]   A[j][i])  
(A[i][j]   !A[j][i]) 
Question 23 Explanation:
First go through the explanation of previous question.
Now, the loop breaks when we found a potential sinkthat is a vertex which does not have any outgoing edge to any coming after it in adjacency matrix.
So, if the column in which this vertex comes is all 1's and the row is all 0's (except diagonal), this is the sink. Otherwise there is no sink in the graph. So, E_{3} is checking this condition. But in the code flag is used for storing the state that sink is present or not. And as per the usage of flag in code, by default sink is considered present.
So, the condition is E_{3} must make flag = 0, if the found i is not a sink. So, the condition should be
A[i][j]   !A[j][i]
So, option (D) is the answer.
Now, the loop breaks when we found a potential sinkthat is a vertex which does not have any outgoing edge to any coming after it in adjacency matrix.
So, if the column in which this vertex comes is all 1's and the row is all 0's (except diagonal), this is the sink. Otherwise there is no sink in the graph. So, E_{3} is checking this condition. But in the code flag is used for storing the state that sink is present or not. And as per the usage of flag in code, by default sink is considered present.
So, the condition is E_{3} must make flag = 0, if the found i is not a sink. So, the condition should be
A[i][j]   !A[j][i]
So, option (D) is the answer.
Question 25 
>100 but finite  
∞  
3  
>3 and ≤100 
Question 25 Explanation:
We consider ABDF at t, they are:
The distance between A and the nodes B, D, F respectively are:
t: 1 2 3
t + 1: 3 2 3
t + 2: 3 4 3
t + 3: 5 4 5
t + 4: 5 6 5
t + 5: 7 6 7
t + 6: 7 8 7
t + 7: 9 8 9
t + 8: 9 to 10
and this continues.
So, in every two steps they get incremented by 2.
So,
at t + 99, F is 101
at t + 100, F is 101.
The distance between A and the nodes B, D, F respectively are:
t: 1 2 3
t + 1: 3 2 3
t + 2: 3 4 3
t + 3: 5 4 5
t + 4: 5 6 5
t + 5: 7 6 7
t + 6: 7 8 7
t + 7: 9 8 9
t + 8: 9 to 10
and this continues.
So, in every two steps they get incremented by 2.
So,
at t + 99, F is 101
at t + 100, F is 101.
Question 26 
Level order traversal of a rooted tree can be done by starting from the root and performing
preorder traversal  
inorder traversal
 
depth first search
 
breadth first search

Question 26 Explanation:
Breadth first search:
It is an algorithm for traversing (or) searching tree (or) graph data structures. It starts at the root and explores all of the neighbour nodes at the present depth prior to moving on to the nodes at the next depth level.
It is an algorithm for traversing (or) searching tree (or) graph data structures. It starts at the root and explores all of the neighbour nodes at the present depth prior to moving on to the nodes at the next depth level.
Question 27 
I, II and IV only  
I and IV only  
II, III and IV only  
I, III and IV only

Question 27 Explanation:
I) a → b → e → g → h → f (✔️)
II) a → b → f → e (✖️)
III) a → b → f → h → g → e (✔️)
IV) a → f → g → h → b → e (✔️)
II) a → b → f → e (✖️)
III) a → b → f → h → g → e (✔️)
IV) a → f → g → h → b → e (✔️)
Question 28 
A[j,k] ≤ n  
If A[j,j] ≥ n  1, then G has a Hamiltonian cycle
 
If there exists a path from j to k, A[j,k] contains the longest path length from j to k  
If there exists a path from j to k, every simple path from j to k contains at most A[j,k] edges

Question 28 Explanation:
Here, we have two functionalities i.e., from j to k, there exists a path then it results otherwise 0.
If there exist a path then it results
A[j,k] = max(A[j,k], A[j,i]+A[i,k])
i.e., if there exists a path from j to k, every simple path from j to k contains the atmost A[j,k] edges.
Question 29 
Let G be an undirected graph. Consider a depthfirst traversal of G, and let T be the resulting depthfirst search tree. Let u be a vertex in G and let ν be the first new (unvisited) vertex visited after visiting u in the traversal. Which of the following statements is always true?
{u, v} must be an edge in G, and u is a descendant of v in T  
{u, v} must be an edge in G, and v is a descendant of u in T  
If {u, v} is not an edge in G then u is a leaf in T  
If {u, v} is not an edge in G then u and v must have the same parent in T 
Question 29 Explanation:
In DFS after visiting u, there is no child node then back tracking is happen and then visit the nodev. There is no need of (u,v) be an edge.
Question 30 
0  
1  
2  
3 
Question 30 Explanation:
Here, vertex 2, 3, 5 are the articulation points. By removing these vertices then the graph will be disconnected.
Total no. of articulation points = 3
Total no. of articulation points = 3
Question 31 
Consider a simple connected graph G with n vertices and nedges (n>2). Then, which of the following statements are true?
G has no cycles.  
The graph obtained by removing any edge from G is not connected.
 
G has at least one cycle.  
The graph obtained by removing any two edges from G is not connected.  
Both C and D. 
Question 31 Explanation:
If a graph have n vertices and n edges (n>2) then it is to be cyclic graph. Then it have atleast one cycle and if we remove two edges then it is not connected.
For example let us consider, n=3
For example let us consider, n=3
Question 32 
How many edges are there in a forest with p components having n vertices in all?
np 
Question 32 Explanation:
Forest is a graph with no cycle.
Now, '0' edges for p1 vertices (p1 components) and np edges for np+1 vertices (1 component).
So, total of np edges for p components.
Now, '0' edges for p1 vertices (p1 components) and np edges for np+1 vertices (1 component).
So, total of np edges for p components.
Question 33 
Consider an undirected unweighted graph G. Let a breadthfirst traversal of G be done starting from a node r. Let d(r,u) and d(r,v) be the lengths of the shortest paths from r to u and v respectively in G. If u is visited before v during the breadthfirst traversal, which of the following statements is correct?
d(r,u)  
d(r,u)>d(r,v)  
d(r,u)≤d(r,v)  
None of the above 
Question 33 Explanation:
d(r,u) and d(r, v) will be equal when u and v are at same level, otherwise d(r,u) will be less than d(r,v).
Question 34 
There is a lineartime algorithm for testing the planarity of finite graphs.
True  
False 
Question 34 Explanation:
Yes, Linear time algorithm is there for testing the planarity of finite graphs.
There are 34 questions to complete.