Graphs

Question 1
   
A
I only
B
II only
C
Both I and II
D
Neither I nor II
       Data-Structures       Graphs       Gate 2018
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.
Question 2
 
A
P only
B
Q only
C
Neither P nor Q
D
Both P and Q
       Data-Structures       Graphs       2016 set-01
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).
Question 3
 
A
12
B
13
C
14
D
15
       Data-Structures       Graphs       2016 set-01
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 (C-B-A-D).
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 efficient algorithm to set the twin pointer in each entry in each adjacency list?
A
Θ(n2)
B
Θ(n+m)
C
Θ(m2)
D
Θ(n4)
       Data-Structures       Graphs       GATE 2016 set-2
Question 4 Explanation: 
Applying BFS on Undirected graph give you twin pointer. Visit every vertex level-wise 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.
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?
A
θ(n)
B
θ(n+m)
C
θ(n2 )
D
θ(m2 )
       Data-Structures       Graphs       GATE 2014(Set-01)
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(V2).
Question 6
 
A
The graph does not have any topological ordering.
B
Both PQRS and SRQP are topological.
C
Both PSRQ and SPRQ are topological orderings.
D
PSRQ is the only topological ordering.
       Data-Structures       Graphs       GATE 2014(Set-01)
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
A
the shortest path between every pair of vertices.
B
the shortest path from W to every vertex in the graph.
C
the shortest paths from W to only those nodes that are leaves of T.
D
the longest path in the graph.
       Data-Structures       Graphs       Gate 2014 Set -02
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.
Question 8
A
19
B
20
C
21
D
22
       Algorithms       Graphs       Gate 2014 Set -03
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
A
7
B
8
C
9
D
10
       Data-Structures       Graphs       2010
Question 9 Explanation: 
The possible minimum path is,
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
A
θ(n)
B
θ(m)
C
θ(m+n)
D
θ(mn)
       Data-Structures       Graphs       Gate-2008
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 θ(n2).
Question 11
 
A
MNOPQR
B
NQMPOR
C
QMNPRO
D
QMNPOR
       Data-Structures       Graphs       Gate-2008
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 edge-disjoint spanning trees. Which of the following is NOT true for G?
A
For every subset of k vertices, the induced subgraph has at most 2k–2 edges
B
The minimum cut in G has at least two edges
C
There are two edge-disjoint paths between every pair to vertices
D
There are two vertex-disjoint paths between every pair of vertices
       Data-Structures       Graphs       Gate-2008
Question 12 Explanation: 
→ In Spanning tree n nodes require n-1 edges. The above question they mentioned 2 disjoint spanning trees. So, it requires n-1 + n-1 =2n-2 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 edge-disjoint spanning trees in G means, between every pair of vertices in G we have two edge-disjoint paths (length of paths may vary).
Question 13
   
A
I and III only
B
II and III only
C
II, III and IV only
D
I, II and III only
       Data-Structures       Graphs       Gate 2008-IT
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.
Question 14
   
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
       Data-Structures       Graphs       Gate-2007
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.
Question 15
A depth-first 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 ?
A
d[u] < d[v]
B
d[u] < f[v]
C
f[u] < f[v]
D
f[u] > f[v]
       Data-Structures       Graphs       Gate 2007-IT
Question 15 Explanation: 

Option A:
d[u] Option B:
d[u] Option C:
f[u] So, option D is True.
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?
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 all its neighbours in G
       Data-Structures       Graphs       Gate-2006
Question 16 Explanation: 
Very difficult assume a graphs here. So, As per the GATE key they given Option D is correct answer.
Question 17
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}
       Data-Structures       Graphs       Gate 2006-IT
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.
Question 18
 
A
There is only one connected component
B
There are two connected components, and P and R are connected
C
There are two connected components, and Q and R are connected
D
There are two connected components, and P and Q are connected
       Data-Structures       Graphs       Gate 2006-IT
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) non-diagonal elements are l's. 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 spanning trees of different costs
       Data-Structures       Graphs       Gate-2005
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 n-1.
Since the weights of every edge is 1 so there are different MST's are possible with same cost, i.e., (n-1).
Question 20
 
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
       Data-Structures       Graphs       Gate-2005
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
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
       Data-Structures       Graphs       Gate-2005
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.
Question 22
 
A
E1 : A[i][j] and E2 : i = j;
B
E1 : !A[i][j] and E2 : i = j + 1;
C
E1: !A[i][j] and E2 : i = j;
D
E1 : A[i][j] and E2 : i = j + 1;
       Theory-of-Computation       Graphs       Gate 2005-IT
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 E2, 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
E1: A[i][j]
and
E2: i = j
E1 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 E2, we must make i = j.
So, answer is (C).
Question 23
A
(A[i][j] && !A[j][i])
B
(!A[i][j] && A[j][i])
C
(!A[i][j] | | A[j][i])
D
(A[i][j] | | !A[j][i])
       Theory-of-Computation       Graphs       Gate 2005-IT
Question 23 Explanation: 
First go through the explanation of previous question.
Now, the loop breaks when we found a potential sink-that 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, E3 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 E3 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 24
 
A
B
C
D
       Theory-of-Computation       Graphs       Gate 2005-IT
Question 24 Explanation: 



Question 25
A
>100 but finite
B
C
3
D
>3 and ≤100
       Theory-of-Computation       Graphs       Gate 2005-IT
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.
Question 26
Level order traversal of a rooted tree can be done by starting from the root and performing
A
preorder traversal
B
in-order traversal
C
depth first search
D
breadth first search
       Data-Structures       Graphs       Gate-2004
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.
Question 27
 
A
I, II and IV only
B
I and IV only
C
II, III and IV only
D
I, III and IV only
       Data-Structures       Graphs       Gate-2003
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 (✔️)
Question 28

A
A[j,k] ≤ n
B
If A[j,j] ≥ n - 1, then G has a Hamiltonian cycle
C
If there exists a path from j to k, A[j,k] contains the longest path length from j to k
D
If there exists a path from j to k, every simple path from j to k contains at most A[j,k] edges
       Algorithms        Graphs       Gate-2003
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 depth-first traversal of G, and let T be the resulting depth-first 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?

A
{u, v} must be an edge in G, and u is a descendant of v in T
B
{u, v} must be an edge in G, and v is a descendant of u in T
C
If {u, v} is not an edge in G then u is a leaf in T
D
If {u, v} is not an edge in G then u and v must have the same parent in T
       Data-Structures       Graphs       Gate-2000
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
   
A
0
B
1
C
2
D
3
       Data-Structures       Graphs       Gate-1999
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
Question 31
Consider a simple connected graph G with n vertices and n-edges (n>2). Then, which of the following statements are true?
A
G has no cycles.
B
The graph obtained by removing any edge from G is not connected.
C
G has at least one cycle.
D
The graph obtained by removing any two edges from G is not connected.
E
Both C and D.
       Algorithms       Graphs       Gate-1993
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
Question 32
How many edges are there in a forest with p components having n vertices in all?
A
n-p
       Data-Structures       Graphs       Gate-1992
Question 32 Explanation: 
Forest is a graph with no cycle.
Now, '0' edges for p-1 vertices (p-1 components) and n-p edges for n-p+1 vertices (1 component).
So, total of n-p edges for p components.
Question 33
Consider an undirected unweighted graph G. Let a breadth-first 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 breadth-first traversal, which of the following statements is correct?
A
d(r,u)
B
d(r,u)>d(r,v)
C
d(r,u)≤d(r,v)
D
None of the above
       Data-Structures       Graphs       Gate-2001
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 linear-time algorithm for testing the planarity of finite graphs.
A
True
B
False
       Data-Structures       Graphs       GATE-1987
Question 34 Explanation: 
Yes, Linear time algorithm is there for testing the planarity of finite graphs.
There are 34 questions to complete.