Question 1
Which of the following is an advantage of adjacency list representation over adjacency matrix representation of a graph?
A
In adjacency list representation, space is saved for sparse graphs.
B
DFS and BSF can be done in O(V + E) time for adjacency list representation. These operations take O(V^2) time in adjacency matrix representation. Here is V and E are number of vertices and edges respectively.
C
Adding a vertex in adjacency list representation is easier than adjacency matrix representation.
D
All of the above
Graph    
Discuss it


Question 2
The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in decreasing order. Which of the following sequences can not be the degree sequence of any graph? I. 7, 6, 5, 4, 4, 3, 2, 1 II. 6, 6, 6, 6, 3, 3, 2, 2 III. 7, 6, 6, 4, 4, 3, 2, 2 IV. 8, 7, 7, 6, 4, 2, 1, 1
A
I and II
B
III and IV
C
IV only
D
II and IV
Graph    
Discuss it


Question 2 Explanation: 
Question 3
The time complexity of computing the transitive closure of a binary relation on a set of n elements is known to be:
A
O(n)
B
O(nLogn)
C
O(n ^ (3/2))
D
O(n^3)
Graph    
Discuss it


Question 4
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) \theta(n) (B) \theta(m) (C) \theta(m + n) (D) \theta(mn)
A
A
B
B
C
C
D
D
Graph    
Discuss it


Question 4 Explanation: 
Connected components can be found in O(m + n) using Tarjan's algorithm. Once we have connected components, we can count them.
Question 5
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. lf u is visited before v during the breadth-first traversal, which of the following statements is correct? (GATE CS 2001)
A
d(r, u) < d (r, v)
B
d(r, u) > d(r, v)
C
d(r, u) <= d (r, v)
D
None of the above
Graph    
Discuss it


Question 5 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 6
How many undirected graphs (not necessarily connected) can be constructed out of a given set V= {V 1, V 2,…V n} of n vertices ?
A
n(n-l)/2
B
2^n
C
n!
D
2^(n(n-1)/2)
Graph    
Discuss it


Question 6 Explanation: 
In an undirected graph, there can be maximum n(n-1)/2 edges. We can choose to have (or not have) any of the n(n-1)/2 edges. So, total number of undirected graphs with n vertices is 2^(n(n-1)/2).
Question 7
Which of the following statements is/are TRUE for an undirected graph? P: Number of odd degree vertices is even Q: Sum of degrees of all vertices is even
A
P Only
B
Q Only
C
Both P and Q
D
Neither P nor Q
Graph    
Discuss it


Question 7 Explanation: 
P is true for undirected graph as adding an edge always increases degree of two vertices by 1. Q is true: If we consider sum of degrees and subtract all even degrees, we get an even number because every edge increases the sum of degrees by 2. So total number of odd degree vertices must be even.
Question 8
Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the expected number of unordered cycles of length three?
A
1/8
B
1
C
7
D
8
Graph    
Discuss it


Question 8 Explanation: 
A cycle of length 3 can be formed with 3 vertices. There can be total 8C3 ways to pick 3 vertices from 8. The probability that there is an edge between two vertices is 1/2. So expected number of unordered cycles of length 3 = (8C3)*(1/2)^3 = 7
Question 9
Given an undirected graph G with V vertices and E edges, the sum of the degrees of all vertices is
A
E
B
2E
C
V
D
2V
Graph    
Discuss it


Question 9 Explanation: 
Since the given graph is undirected, every edge contributes as 2 to sum of degrees. So the sum of degrees is 2E.
Question 10
How many undirected graphs (not necessarily connected) can be constructed out of a given set V = {v1, v2, ... vn} of n vertices?
A
n(n-1)/2
B
2n
C
n!
D
2n(n-1)/2
Graph    GATE-CS-2001    
Discuss it


Question 10 Explanation: 
There are total n*(n-1)/2 possible edges. For every edge, there are to possible options, either we pick it or don't pick. So total number of possible graphs is 2n(n-1)/2.
Question 11
What is the maximum number of edges in an acyclic undirected graph with n vertices?
A
n-i
B
n
C
n + 1
D
2n-1
Graph    GATE-IT-2004    
Discuss it


Question 11 Explanation: 
n * (n - 1) / 2 when not cyclic. An acyclic graph with the maximum number of edges is actually a spanning tree and therefore, correct answer is n-1 edges. So Answer is A
Question 12
Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G containing the edge e. Which of the following statements is always TRUE?  
A
There exists a cutset in G having all edges of maximum weight.
B
There exists a cycle in G having all edges of maximum weight
C
Edge e cannot be contained in a cycle.
D
All edges in G have the same weight
Graph    Gate IT 2005    
Discuss it


Question 12 Explanation: 
Background : Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together.
  1. A spanning tree has exactly V - 1 edges.
  2. A single graph can have many different spanning trees. A minimum spanning tree (MST) or minimum weight spanning tree for a weighted, connected and undirected graph is a spanning tree with weight less than or equal to the weight of every other spanning tree. The weight of a spanning tree is the sum of weights given to each edge of the spanning tree.
  3. There can be more that one possible spanning trees of a graph. For example, the graph in this question has 6 possible spanning trees.
  4. MST has lightest edge of every cutset. Remember Prim's algorithm which basically picks the lightest edge from every cutset.
Choices of this question : a) There exists a cutset in G having all edges of maximum weight : This is correct. If there is a heaviest edge in MST, then there exist a cut with all edges with weight equal to heavies edge. See point 4 discussed in above background. mst b) There exists a cycle in G having all edges of maximum weight : Not always TRUE. The cutset of heaviest edge may contain only one edge. In fact there may be overall one edge of heavies weight which is part of MST (Consider a graph with two components which are connected by only one edge and this edge is the heavies) c) Edge e cannot be contained in a cycle. Not Always True. The curset may form cycle with other edges. d) All edges in G have the same weight Not always True. As discussed in option b, there can be only one edge of heaviest weight.
Question 13
Q84 Part_B
A sink in a directed graph is a vertex i such that there is an edge from every vertex j ≠ i to i and there is no edge from i to any other vertex. A directed graph G with n vertices is represented by its adjacency matrix A, where A[i] [j] = 1 if there is an edge directed from vertex i to j and 0 otherwise. The following algorithm determines whether there is a sink in the graph G.
i = 0
do {
    j = i + 1;
    while ((j < n) && E1) j++;
    if (j < n) E2;
} while (j < n);

flag = 1;
for (j = 0; j < n; j++)
    if ((j! = i) && E3)
        flag = 0;

if (flag)
    printf("Sink exists");
else
    printf("Sink does not exist");
Choose the correct expressions for E3  
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])
Graph    Gate IT 2005    
Discuss it


Question 13 Explanation: 
Below explanation is for Previous Part of this question: For vertex i to be a sink, there should be no edge from i to any other vertex. sink According the input given in question,
A[i][j] = 1 means there is an edge from vertex i to j.
A[i][j] = 0 means there is no edge from i to j
For a node to i to be sink,
A[i][j] should be 0 for all j 
A[j][i] should be 1 for all j.
The above pseudo code checks every vertex i for sink, starting from i = 0. It basically checks every vertex j after i for being a sink. The trick in pseudo code is, it doesn't check for j smaller than i. The i picked by this loop may not be sink. It basically makes sure that we don't ignore a potential sink. The check whether i is actually a sink or not is done later after do while loop. Vertex i is a potential sink while A[i][j] is zero Thus, E1 : !A[i][j] If the above condition is false, then i is not a sink. All j < i can also not be a sink because there is no edge from i to j. Now, the next potential sink can be j. So, E2 : i = j Explanation for this question The following pseudo code basically checks if the potential sink picked by the code above is actually a sink or not.
flag = 1;
for (j = 0; j < n; j++)
    if ((j! = i) && E3)
        flag = 0;
flag equals to 0 means i is not a sink. The code sets the flag 0 as soon as it finds out that i is not a sink.
A node i is not a sink if either of the following 
two conditions become true for any j not equal to i.
A[i][j] is 1 for any j 
OR
A[j][i] is 0 for any j
E3 : (A[i][j] | | !A[j][i]) Therefore option D is correct
Question 14
Q85  Part_A Consider a simple graph with unit edge costs. Each node in the graph represents a router. Each node maintains a routing table indicating the next hop router to be used to relay a packet to its destination and the cost of the path to the destination through that router. Initially, the routing table is empty. The routing table is synchronously updated as follows. In each updation interval, three tasks are performed.
  1. A node determines whether its neighbours in the graph are accessible. If so, it sets the tentative cost to each accessible neighbour as 1. Otherwise, the cost is set to ∞.
  2. From each accessible neighbour, it gets the costs to relay to other nodes via that neighbour (as the next hop).
  3. Each node updates its routing table based on the information received in the previous two steps by choosing the minimum cost.
download
For the graph given above, possible routing tables for various nodes after they have stabilized, are shown in the following options. Identify the correct table.
1) Table for node A
 A  -  -
 B  B  1
 C  C  1
 D  B  3
 E  C  3
 F  C  4
2) Table for node C
 A  A  1
 B  B  1
 C  -  -
 D  D  1
 E  E  1
 F  E  3
3)
Table for node B
 A  A  1
 B  -  -
 C  C  1
 D  D  1
 E  C  2
 F  D  2
4) Table for node D
 A  B  3
 B  B  1
 C  C  1
 D  - -
 E  E  1
 F  F  1
A
A
B
B
C
C
D
D
Graph    Gate IT 2005    
Discuss it


Question 14 Explanation: 
graph_05_90 graph_05_90_1   This solution is contributed by Sandeep Pandey.
Question 15
Q85 Part_B Consider a simple graph with unit edge costs. Each node in the graph represents a router. Each node maintains a routing table indicating the next hop router to be used to relay a packet to its destination and the cost of the path to the destination through that router. Initially, the routing table is empty. The routing table is synchronously updated as follows. In each updation interval, three tasks are performed.
  1. A node determines whether its neighbours in the graph are accessible. If so, it sets the tentative cost to each accessible neighbour as 1. Otherwise, the cost is set to ∞.
  2. From each accessible neighbour, it gets the costs to relay to other nodes via that neighbour (as the next hop).
  3. Each node updates its routing table based on the information received in the previous two steps by choosing the minimum cost.
download
For the graph given above, possible routing tables for various nodes after they have stabilized, are shown in the following options. Identify the correct table.
1) Table for node A
 A  -  -
 B  B  1
 C  C  1
 D  B  3
 E  C  3
 F  C  4
2) Table for node C
 A  A  1
 B  B  1
 C  -  -
 D  D  1
 E  E  1
 F  E  3
3)
Table for node B
 A  A  1
 B  -  -
 C  C  1
 D  D  1
 E  C  2
 F  D  2
4) Table for node D
 A  B  3
 B  B  1
 C  C  1
 D  - -
 E  E  1
 F  F  1
Continuing from the earlier problem, suppose at some time t, when the costs have stabilized, node A goes down. The cost from node F to node A at time (t + 100) is  
A
>100 but finite
B
C
3
D
>3 and ≤100
Graph    Gate IT 2005    
Discuss it


Question 16
The cyclomatic complexity of the flow graph of a program provides  
A
an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at most once
B
a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at most once
C
an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once
D
a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at least once
Graph    Software Engineering    GATE IT 2006    
Discuss it


Question 17
What is the largest integer m such that every simple connected graph with n vertices and n edges contains at least m different spanning trees?
A
1
B
2
C
3
D
n
Graph    Graph Minimum Spanning Tree    Gate IT 2007    
Discuss it


Question 17 Explanation: 
A graph is connected iff all nodes can be traversed from each node. For a graph with n nodes, there will be n-1 minimum number of edges.
Given that there are n edges, that means a cycle is there in the graph.
The simplex graph with these conditions may be:
2007_25
Now we can make a different spanning tree by removing one edge from the cycle, one at a time.
Minimum cycle length can be 3, So, there must be atleast 3 spanning trees in any such Graph.
Question 18
For the undirected, weighted graph given below, which of the following sequences of edges represents a correct execution of Prim's algorithm to construct a Minimum Span­ning Tree?
2008_45
A
(a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
B
(c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
C
(d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
D
(h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
Graph    Gate IT 2008    
Discuss it


Question 18 Explanation: 
In prims algorithm we start with any node and keep on exploring minimum cost neighbors of nodes already covered.
Question 19
Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?
A
O(m+n)
B
O(m logn)
C
O(mn)
D
O(n logm)
Graph    GATE 2017 Mock    
Discuss it


Question 19 Explanation: 
It’s a special case in which all edge weights are equal, so dfs would work and resultant depth first tree would be the spanning tree. So the answer would be O(m+n).
Question 20
You are given a graph containing n vertices and m edges and given that the graph doesn’t contain cycle of odd length. Time Complexity of the best known algorithm to find out whether the graph is bipartite or not is ?
A
O(m+n)
B
O(1)
C
O(mn)
D
O(n2)
Graph    GATE 2017 Mock    
Discuss it


Question 20 Explanation: 
It is by definition that a graph is bipartite iff it does not contain odd length cycles. So the answer is O(1).
For more background reading, check this link https://proofwiki.org/wiki/Graph_is_Bipartite_iff_No_Odd_Cycles
Question 21
Let G be a simple graph with 20 vertices and 8 components. If we delete a vertex in G, then number of components in G should lie between ____.
A
8 and 20
B
8 and 19
C
7 and 19
D
7 and 20
Graph    GATE 2017 Mock    
Discuss it


Question 21 Explanation: 
Case 1: If the vertex we are deleting from G is an isolated vertex, which is a component by itself, then number of components in G becomes 7.
Case 2: If G is a start Graph, then by deleting the cut vertex of G, we get 19 components.
Hence, number of components in G should lie between 7 and 19.
There are 21 questions to complete.

GATE CS Corner


See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.