Graph Algorithms: past questions

42 questions · 134 marks · 10 papers. Try each one before checking.

Solve them and check answers →Read the notes first

03 Aug 2025

Question 2 MCQ · 4 marks

Consider the following graph.

If Dijkstra's algorithm is used with vertex A as the source vertex, what are the shortest distances from vertex A to all vertices in the graph?

This question has a figure: open the interactive page.

  1. Vertex A B C D E F G
    Shortest distance 0 2 3 1 4 8 5
  2. Vertex A B C D E F G
    Shortest distance 0 2 3 1 3 6 5
  3. Vertex A B C D E F G
    Shortest distance 0 2 3 1 5 8 4
  4. Vertex A B C D E F G
    Shortest distance 0 2 3 1 4 6 5

Question 12 MSQ · 3 marks

Which of the following is/are True about Bellman-Ford algorithm?

  1. It can handle disconnected graphs.

  2. The shortest path is not stabilized, if there are negative cycles.

  3. It can handle negative edge weights, but not negative cycles.

  4. It uses the greedy approach to find the shortest path.

Question 4 MCQ · 3 marks

Consider the given statements below about Prim's algorithm's behaviour and properties. i. The choice of the starting vertex can lead to different Minimum Spanning Trees if multiple MSTs exist with the same total weight. ii. Prim's algorithm first sorts all edges in the graph by weight. iii. The algorithm maintains a set of visited vertices and, at each step, selects the minimum weight edge connecting a visited vertex to an unvisited vertex.

Which of the given statements are True?

  1. Statements i and ii

  2. Statements ii and iii

  3. Statements i and iii

  4. All statements i, ii and iii

Question 15 SA · 3 marks

The weight of the minimum spanning tree of the graph G given below ___.

This question has a figure: open the interactive page.

Type your answer on the interactive page.

July 2022

Question 11 MSQ · 4 marks

Consider the following graph.

Apply Dijkstra's algorithm from vertex A in the given graph. Which of the following statement(s) is/are true?

This question has a figure: open the interactive page.

  1. If A is the 1st visited vertex, then The 5th visited marked vertex is F

  2. The shortest path cost from A to G is 33

  3. There is exactly one path with minimum cost from A to F

  4. More than one path with the same minimum cost are available from A to G

Question 8 MSQ · 3 marks

Which of the following statement(s) is/are true?

  1. Given a graph where all edges have positive weights, the shortest path produced by Dijkstra's and Bellman-Ford algorithm may be different, but the path weight would be the same.

  2. Given a graph where weights of all edges are unique, there is always a unique shortest path from a source to destination in such a graph.

  3. Bellman-Ford and Floyd-Warshall's algorithm can calculate the shortest path correctly if the graph has negative edge weights but does not have negative weight cycles.

  4. The time complexity of Floyd-Warshall is $O(V^2)$, where $V$ is the number of vertices in the graph.

Question 2 MCQ · 3 marks

Consider the following graph $G$.

Choose a value for $x$ that will maximize the number of minimum cost spanning trees [MCSTs] for graph $G$. The number of minimum cost spanning trees [MCSTs] of $G$ for this value of $x$ is ___

This question has a figure: open the interactive page.

  1. 1

  2. 3

  3. 4

  4. 5

Question 9 MSQ · 3 marks

Let $G = (V, E)$ be an undirected connected graph with more than two vertices where each edge has a distinct weight, and $e$ is a particular edge of $G$. Which of the following statement(s) is/are always true about the minimum cost spanning trees (MCSTs) of $G$ ?

  1. If $e$ is the lightest weight edge of some cycle in $G$, then MCST of $G$ includes $e$

  2. If $e$ is the heaviest weight edge of some cycle in $G$, then MCST of $G$ excludes $e$

  3. If $e$ is the heaviest weight edge in $G$, then MCST of $G$ excludes $e$

  4. If $e$ is the lightest weight edge in $G$, then MCST of $G$ includes $e$

01 Dec 2024

Question 3 MCQ · 3 marks

Consider the following graph

If the Dijkstra algorithm is used with B as the source vertex, then what is the order in which all other vertices are visited?

This question has a figure: open the interactive page.

  1. B, E, C, F, A, D, G

  2. B, E, F, A, C, G, D

  3. B, E, F, C, A, G, D

  4. B, E, F, A, C, D, G

Question 2 MCQ · 3 marks

Match the following algorithms with related statements.

Algorithms Statements
A Dijkstra's Algorithm I Find the shortest path between all pairs of vertices in a graph with positive or negative weights but without negative weight cycle
B Floyd-Warshall Algorithm II Find the shortest path from source vertex to all other vertices in a weighted graph with non-negative edge weights
C Bellman-Ford Algorithm III Find the shortest path from source vertex to all other vertices in a weighted graph with with positive or negative weights but without negative weight cycle
D Prims's Algorithm IV To find a subset of edges from the graph that connects all the vertices together, without any cycles, and with the minimum possible total edge weight.

Chose the correct matching from the options given below.

  1. A-II, B-I, C-III, D-IV

  2. A-II, B-I, C-IV, D-III

  3. A-I, B-II, C-III, D-IV

  4. A-III, B-II, C-IV, D-I

Question 4 MCQ · 3 marks

Consider the following statement.

  1. When we implement Prim's algorithm using min-heap the time complexity is improved to $O((m+n)\log n)$.
  1. When we implement Dijkstra's algorithm using min-heap the time complexity is improved to $O((m+n)\log n)$.

Which of the following option is correct?

  1. Only statement 1 is correct.

  2. Only statement 2 is correct.

  3. Both statements are correct.

  4. Both statements are incorrect.

Question 16 MCQ · 4 marks

Consider the following modified pseudocode for FindSet and UnionSet operation for Disjoint Set Union data structure:

1  Component[n] // An array of size n initialized as Component[i] = i
2  FindSet(u):
3      If (Component[u] == u):
4          return u
5      return FindSet(Component[u])
6
7  UnionSet(u, v):
8      x = FindSet(u)
9      y = FindSet(v)
10     If (x != y):
11         Component[y] = x

You are given an array Component representing the Component array of a Disjoint Set Union (DSU) data structure for 8 vertices labelled from 0 to 7. Suppose after performing a series of UnionSet operations using the provided pseudocode, the Component array becomes:

v 0 1 2 3 4 5 6 7
Component[v] 0 1 2 1 3 4 3 5

What will be the result of the operation FindSet(7)?

  1. 1

  2. 2

  3. 3

  4. 0

Question 14 MSQ · 3 marks

Let $w$ be the minimum weight among all edge weights in an undirected connected graph $G$. Let $e$ be a specific edge of weight $w$. Which of the following statement(s) is/are true?

  1. There is a minimum spanning tree containing edge $e$.

  2. If edge $e$ is not present in a minimum spanning tree $T$, then in the cycle formed by adding edge $e$ to $T$, all edges have the same weight $w$.

  3. edge $e$ is present in every minimum spanning tree of graph $G$.

  4. edge $e$ is not present in any minimum spanning tree of graph $G$.

Question 10 SA · 3 marks

Consider the following graph.

The weight of minimum spanning trees of given graph is ___.

This question has a figure: open the interactive page.

Type your answer on the interactive page.

06 Apr 2026

Question 1 MCQ · 3 marks

Which of the following statements is/are correct about Dijkstra's algorithm to find the shortest path? I. The shortest path returned by Dijkstra's algorithm always passes through the least number of vertices. II. To decide which vertex to visit next, Dijkstra's algorithm selects the vertex with the minimum known distance among all unvisited vertices.

  1. Only I is correct

  2. Only II is correct

  3. Both I and II are correct

  4. Both I and II are incorrect

Question 2 MCQ · 3 marks

The Bellman-Ford algorithm can be used to detect the presence of a negative-weight cycle reachable from the source vertex in a weighted directed graph. Which of the following correctly explains how Bellman-Ford detects a negative-weight cycle?

  1. A negative-weight cycle exists if the shortest distance to any vertex becomes negative at any point during the algorithm.

  2. If, after performing exactly $V-1$ relaxation iterations, an additional relaxation of any edge further reduces a distance value, then a negative-weight cycle is present.

  3. If the algorithm encounters an edge with a negative weight during relaxation, it immediately concludes that a negative-weight cycle exists.

  4. If multiple shortest paths exist between two vertices, the graph must contain a negative-weight cycle.

Question 11 MSQ · 3 marks

Let $G$ be a connected complete graph with 4 vertices and 6 edges, where all edge weights are distinct and ordered as: $e_1 < e_2 < e_3 < e_4 < e_5 < e_6$. Which of the following sets of edges can be in a minimum cost spanning tree of $G$? (Select all that apply.)

  1. $\{e_1, e_2, e_3\}$

  2. $\{e_2, e_3, e_4\}$

  3. $\{e_1, e_3, e_4\}$

  4. $\{e_1, e_2, e_4\}$

  5. $\{e_1, e_2, e_3, e_4\}$

Question 13 SA · 4 marks

Consider the given weighted adjacency matrix $w$ for a complete undirected graph with vertex set $\{0, 1, 2, 3, 4\}$. Where $w[i][j], i \neq j$ in the matrix is the weight of the edge $(i, j)$.

$$w = \begin{pmatrix} 0 & 3 & 6 & 2 & 5 \\ 3 & 0 & 4 & 7 & 8 \\ 6 & 4 & 0 & 9 & 1 \\ 2 & 7 & 9 & 0 & 3 \\ 5 & 8 & 1 & 3 & 0 \end{pmatrix}$$

What is the total weight of the minimum spanning tree (MST) for the given graph?

Type your answer on the interactive page.

Aug 2023

Question 3 MSQ · 3 marks

Which of the following statements is true about Dijkstra's algorithm to find the shortest path?

  1. Dijkstra's algorithm may fail for graphs with negative weights because it does not reconsider a node once it marks it as visited, even if a shorter path exists than the previous one.

  2. The shortest path between two vertices $u$ and $v$ in a graph $G$ always remains unaltered when all the edges of $G$ are incremented by an equal amount.

  3. The shortest path between two vertices $u$ and $v$ in a graph $G$ always remains unaltered when all the edges of $G$ are multiplied by a positive integer.

  4. To decide which node to visit next, Dijkstra's algorithm selects the node with the smallest known distance.

Question 2 MCQ · 3 marks

Consider the following strategy to solve the single source shortest path problem with positive integer edge weights from a source vertex $s$: Replace each edge with weight $w$ by $w$ edges of weight 1 connected by new intermediate nodes. Run $\text{BFS}(s)$ on the modified graph to find the shortest path to each of the original vertices in the graph. Which of the following statement is true?

  1. This strategy will not solve the problem correctly.

  2. This strategy will only work if the graph is acyclic.

  3. This strategy will solve the problem correctly and is as efficient as Dijkstra's algorithm.

  4. This strategy will solve the problem correctly, but is not as efficient as Dijkstra's algorithm.

Question 5 MCQ · 3 marks

Let $G = (V, E)$ be an undirected graph having distinct positive edge weights. Let $V$ be partitioned into two non-empty sets $X$ and $Y$. Let $e = (s, t)$ be the minimum cost edge, with $s$ belonging to $X$ and $t$ belonging to $Y$. Which of the following statement(s) is/are true?

  1. The edge $e$ must definitely belong to each path from $s$ to $t$.
  1. The edge $e$ must definitely belong to the minimum cost spanning tree of $G$.
  1. Only 1

  2. Only 2

  3. Both 1 and 2

  4. Neither 1 nor 2

Question 4 SA · 3 marks

Consider the graph $G$ given below.

Let $\alpha$ denote the number of minimum spanning trees of $G$ and $\beta$ denote the weight of such a minimum spanning tree. The value of $\alpha + \beta$ ___

This question has a figure: open the interactive page.

Type your answer on the interactive page.

Dec 2023

Question 2 MCQ · 3 marks

Consider the following directed graph.

If Dijkstra's algorithm is used with a as the source vertex, then what is the order in which all vertices are visited? Note: Assume that when multiple unvisited nodes have the same minimum distance, Dijkstra's algorithm visits them alphabetically.

This question has a figure: open the interactive page.

  1. a, b, c, d, e

  2. a, b, c, e, d

  3. a, b, d, c, e

  4. a, b, d, e, c

Question 14 MSQ · 3 marks

Consider the following graph.

Which of the following statement(s) is/are true about computing the shortest path distance from vertex a to other vertices in the given graph?

This question has a figure: open the interactive page.

  1. Dijkstra's algorithm computes the correct shortest path distance.

  2. Dijkstra's algorithm does not compute the correct shortest path distance.

  3. Bellman-Ford algorithm computes the correct shortest path distance.

  4. Bellman-Ford algorithm does not compute the correct shortest path distance.

  5. Floyd Warshall algorithm computes the correct shortest path distance.

Question 3 MCQ · 3 marks

Let $G = (V, E)$ be an undirected graph having distinct positive edge weights. Let $V$ be partitioned into two non-empty sets $X$ and $Y$. Let $e = (s, t)$ be the minimum cost edge, with $s$ belonging to $X$ and $t$ belonging to $Y$. Which of the following statement(s) is/are true?

  1. The edge $e$ must belong to each path from $s$ to $t$.
  1. The edge $e$ must belong to the minimum cost spanning tree of $G$.
  1. Only 1

  2. Only 2

  3. Both 1 and 2

  4. Neither 1 nor 2

Question 11 SA · 4 marks

Consider the graph $G$ given below.

The cost of the minimum cost spanning tree for the given graph is ___

This question has a figure: open the interactive page.

Type your answer on the interactive page.

16 Mar 2025

Question 2 MCQ · 3 marks

Consider the following directed weighted graph.

Dijkstra's algorithm runs with vertex P as the source vertex. In what order do the nodes get included in the visited set? Note: If two vertices have the same minimum distance, then the algorithm picks the next vertex which comes first alphabetically.

This question has a figure: open the interactive page.

  1. PRTSUQV

  2. PRTSQUV

  3. PRTUSVQ

  4. PRTSUVQ

Question 12 MSQ · 3 marks

Which of the following is/are always true about the Floyd-Warshall algorithm?

  1. If the shortest path entry sp[i][i] in the resultant matrix is negative, then it represents the graph has a negative weight cycle.

  2. The time complexity of Floyd-Warshall is $O(V^2)$, where $V$ is the number of vertices in the graph.

  3. It works correctly if the graph has negative edge weights but does not have negative weight cycles.

  4. The formula to compute the shortest path from vertex $i$ to $j$ is $SP^k[i, j] = \min[SP^{k-1}[i, j] + SP^{k-1}[i, k], SP^{k-1}[k, j]]$

Question 17 SA · 3 marks

Based on the above data, answer the given subquestions. Consider the following graph G.

Child question. What is the smallest value of X such that the edge (A, E) is excluded from every minimum spanning tree of the graph?

This question has a figure: open the interactive page.

Type your answer on the interactive page.

Question 18 SA · 3 marks

Based on the above data, answer the given subquestions. Consider the following graph G.

Child question. What value of X will make the total cost of the minimum spanning tree of G equal to 10?

This question has a figure: open the interactive page.

Type your answer on the interactive page.

24 Mar 2024

Question 3 MCQ · 3 marks

Consider the following graph.

If Dijkstra's algorithm is used with P as the source vertex then what is the order in which all vertices are visited?

This question has a figure: open the interactive page.

  1. P, Q, R, U, T, S

  2. P, Q, R, S, T, U

  3. P, Q, R, S, U, T

  4. P, Q, R, U, S, T

Question 2 MCQ · 2 marks

In the context of the Floyd-Warshall algorithm, what does it mean if the distance matrix has a negative value in its diagonal?

  1. The graph has a negative-weight cycle.

  2. The graph has negative-weight on edge but no negative-weight cycle.

  3. The graph is acyclic.

  4. The graph has a disconnected component.

Question 9 MCQ · 4 marks

Consider the following graph.

If Prim's algorithm started with vertex a to construct a Minimum Spanning Tree, then what is the order in which vertices are marked visited?

This question has a figure: open the interactive page.

  1. a, e, b, c, d, g, h, f

  2. a, e, b, c, g, h, d, f

  3. a, e, b, d, c, h, g, f

  4. a, e, b, d, c, g, f, h

Question 13 MSQ · 4 marks

Consider the following graph where w1, w2, w3, w4, and w5 represent the weights on edges.

Which of the following statement(s) is/are always true for the Minimum Spanning Tree(MST)?

This question has a figure: open the interactive page.

  1. If all given weights are distinct, then only one unique MST is possible.

  2. If w1 and w2 are the same and largest among all weights and other weights are distinct, then only one unique MST is possible.

  3. If w1 and w3 are the same and largest among all weights and other weights are distinct, then only one unique MST is possible.

  4. If w1 and w4 are the same and smallest among all weights and other weights are distinct, then only one unique MST is possible.

04 Aug 2024

Question 2 MCQ · 4 marks

Consider the following graph

If the Dijkstra algorithm is used with A as the source vertex, then what is the order in which all other vertices are visited?

This question has a figure: open the interactive page.

  1. A, C, F, B, E, D

  2. A, C, F, B, D, E

  3. A, C, B, F, E, D

  4. A, C, B, F, D, E

Question 4 MCQ · 3 marks

Consider a directed graph $G$ with equal edge weights. Which of the following algorithms is most efficient to compute the shortest distance between every pair of nodes in $G$?

  1. Run BFS once on every node

  2. Run Dijkstra's algorithm once on every node

  3. Run Bellman Ford's algorithm once on every node

  4. Run Floyd-Warshall algorithm

Question 5 MCQ · 3 marks

Consider an undirected connected graph $G$ with $V$ vertices, where all edge costs are distinct. Which of the following statement(s) is/are true?

  1. Let $V$ be partitioned into two non-empty sets $X$ and $Y$. Let $e = (s, t)$ be the minimum cost edge, with $s$ belonging to $X$ and $t$ belonging to $Y$. Then edge $e$ must definitely belong to the minimum cost spanning tree of $G$.
  1. Let $C$ be any cycle in $G$, and let edge $e = (u, v)$ be the most expensive edge belonging to $C$. Then edge $e$ does not belong to the minimum spanning tree of $G$.
  1. Only 1

  2. Only 2

  3. Both 1 and 2

  4. Neither 1 nor 2

Question 12 SA · 3 marks

Let $G$ be a complete undirected graph with 5 vertices and 10 edges with weights of 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. The maximum possible weight that a minimum weight spanning tree of $G$ can have is ___

Type your answer on the interactive page.

14 Aug 2026

Question 1 MSQ · 3 marks

Which of the following statements is true about Dijkstra's algorithm to find the shortest path?

  1. Dijkstra's algorithm may fail for graphs with negative weights because it does not reconsider a node once it marks it as visited, even if there is a shorter path than the previous one.

  2. The shortest path between two vertices $u$ and $v$ in a graph $G$ always remains unaltered when all the edges of $G$ are incremented by an equal amount.

  3. The shortest path between two vertices $u$ and $v$ in a graph $G$ always remains unaltered when all the edges of $G$ are multiplied by a positive integer.

  4. To decide which node to visit next, Dijkstra's algorithm selects the unvisited node with the smallest known distance.

Question 3 MCQ · 3 marks

Which of the following statements about the Floyd-Warshall algorithm is correct?

  1. It can compute shortest paths only in graphs with non-negative edge weights.

  2. It computes shortest paths from a single source vertex to all other vertices.

  3. It computes shortest paths between every pair of vertices and can handle negative edge weights, provided there is no negative cycle.

  4. It requires the graph to be acyclic.

Question 2 MCQ · 3 marks

Let $G = (V, E)$ be an undirected graph having distinct positive edge weights. Let $V$ be partitioned into two non-empty sets $X$ and $Y$. Let $e = (s, t)$ be the minimum cost edge, with $s$ belonging to $X$ and $t$ belonging to $Y$. Which of the following statement(s) is/are true?

  1. The edge $e$ must belong to each path from $s$ to $t$.
  1. The edge $e$ must belong to the minimum cost spanning tree of $G$.
  1. Only 1

  2. Only 2

  3. Both 1 and 2

  4. Neither 1 nor 2

Question 13 SA · 4 marks

Consider the undirected, weighted graph $G$ with vertices $V = \{a, b, c, d\}$ and the following edge weights:

Let $\alpha$ denote the total number of distinct Minimum Spanning Trees (MSTs) of $G$, and let $\beta$ denote the total weight of any such Minimum Spanning Tree. What is the value of $\alpha + \beta$?

This question has a figure: open the interactive page.

Type your answer on the interactive page.

Check your answers →

Other PDSA topics