250+ TOP MCQs on Directed Graph and Answers

Data Structure Multiple Choice Questions on “Directed Graph”.

1. Dijkstra’s Algorithm will work for both negative and positive weights?
a) True
b) False
Answer: b
Clarification: Dijkstra’s Algorithm assumes all weights to be non-negative.

2. A graph having an edge from each vertex to every other vertex is called a ___________
a) Tightly Connected
b) Strongly Connected
c) Weakly Connected
d) Loosely Connected
Answer: a
Clarification: This is a part of the nomenclature followed in Graph Theory.

3. What is the number of unlabeled simple directed graph that can be made with 1 or 2 vertices?
a) 2
b) 4
c) 5
d) 9
Answer: b
Clarification:data-structure-questions-answers-directed-graph-q3

4. Floyd Warshall Algorithm used to solve the shortest path problem has a time complexity of __________
a) O(V*V)
b) O(V*V*V)
c) O(E*V)
d) O(E*E)
Answer: b
Clarification: The Algorithm uses Dynamic Programming and checks for every possible path.

5. All Graphs have unique representation on paper.
a) True
b) False
Answer: b
Clarification: Same Graph may be drawn in different ways on paper.

6. Assuming value of every weight to be greater than 10, in which of the following cases the shortest path of a directed weighted graph from 2 vertices u and v will never change?
a) add all values by 10
b) subtract 10 from all the values
c) multiply all values by 10
d) in both the cases of multiplying and adding by 10
Answer: c
Clarification: In case of addition or subtraction the shortest path may change because the number of edges between different paths may be different, while in case of multiplication path wont change.

7. What is the maximum possible number of edges in a directed graph with no self loops having 8 vertices?
a) 28
b) 64
c) 256
d) 56
Answer: d
Clarification: If a graph has V vertices than every vertex can be connected to a possible of V-1 vertices.

8. What would be the DFS traversal of the given Graph?
data-structure-questions-answers-directed-graph-q8
a) ABCED
b) AEDCB
c) EDCBA
d) ADECB
Answer: a
Clarification: In this case two answers are possible including ADEBC.

9. What would be the value of the distance matrix, after the execution of the given code?

#include 
#define INF 1000000
int graph[V][V] = {   {0,   7,  INF, 4},
                      {INF, 0,   13, INF},
                      {INF, INF, 0,   12},
                      {INF, INF, INF, 0}
                  };
 
int distance[V][V], i, j, k;
 
for (i = 0; i < V; i++)
        for (j = 0; j < V; j++)
    	distance[i][j] = graph[i][j];
 
for (k = 0; k < V; k++)
	for (i = 0; i < V; i++)
        	for (j = 0; j < V; j++)
                {
            		if (distance[i][k] + distance[k][j] < distance[i][j])
                		distance[i][j] = distance[i][k] + distance[k][j];
 
                           return 0;
                }

a)

{            
    {0,   7,  INF, 4},
    {INF, 0,   13, INF},
    {INF, INF, 0,   12},
    {INF, INF, INF, 0}
};

b)

{            
    {0,   7,  20, 24},
    {INF, 0,   13, 25},
    {INF, INF, 0,   12},
    {INF, INF, INF, 0}
};

c)

{ 
    {0,   INF,  20, 24},
    {INF, INF,   13, 25},
    {INF, INF, 0,   12},
    {INF, INF, INF, 0}
    {INF, 0,   13, 25},
    {INF, INF, 0,   12},
    {24, INF, INF, 0}
};

d) None of the mentioned
Answer: b
Clarification: The program computes the shortest sub distances.

10. What is the maximum number of edges present in a simple directed graph with 7 vertices if there exists no cycles in the graph?
a) 21
b) 7
c) 6
d) 49
Answer: c
Clarification: If the no cycles exists then the difference between the number of vertices and edges is 1.

Leave a Reply

Your email address will not be published. Required fields are marked *