Graph Theory and Graph Algorithms · Programming, Data Structures and Algorithms
4 questions · asked in 3 of 3 years (2024–2026)
MCQ 1 · MSQ 2 · NAT 12-mark 4
2024Questions per year2026
Questions 1–4 of 4
Consider a directed graph , where is the finite set of vertices and is the set of directed edges between the vertices. may contain cycles but there is no self-loop. Further, may not be strongly connected.
Let be the graph obtained by reversing the directions of all the edges in without changing the set of vertices.
Assume that Breadth First Search (BFS) or Depth First Search (DFS) from any given vertex of a graph visits only the reachable vertices from in that graph.
Which of the following statements must always be true, regardless of the structure of
Let be the graph obtained by reversing the directions of all the edges in without changing the set of vertices.
Assume that Breadth First Search (BFS) or Depth First Search (DFS) from any given vertex of a graph visits only the reachable vertices from in that graph.
Which of the following statements must always be true, regardless of the structure of
Answer: (D)
Say is reached from in . Then there is a directed path in . Reversing every edge on it gives a directed path in . So is reachable from in , and BFS from visits every reachable vertex, in whatever order. So (D) is always true.
For A, B and C take with a single edge . Then has the edge .
- (A): BFS of from reaches , but DFS of from reaches only . False.
- (B): the two visited sets are and , which differ. False.
- (C): the BFS order is and the DFS order is . Reversing does not give . False.
Answer: (D)
For A, B and C take with a single edge . Then has the edge .
- (A): BFS of from reaches , but DFS of from reaches only . False.
- (B): the two visited sets are and , which differ. False.
- (C): the BFS order is and the DFS order is . Reversing does not give . False.
Answer: (D)
Let be a simple, unweighted, and undirected graph. A subset of the vertices and edges of are shown below.
It is given that is a shortest path between and is a shortest path between and is a shortest path between and . Which of the following is/are NOT the edges of ?
It is given that is a shortest path between and is a shortest path between and is a shortest path between and . Which of the following is/are NOT the edges of ?
One or more options are correct.
Answer: (A), (C), (D)
The edges shown are a-b, b-c, c-d, a-f, e-f, f-c, f-g, c-h, g-h. Each given path has length and is a shortest path. An extra edge cannot exist if it gives a path shorter than between one of these pairs.
- (b,d): has length , shorter than the shortest path of length . Cannot exist.
- (b,h): has length , shorter than the shortest path of length . Cannot exist.
- (e,g): has length , shorter than the shortest path of length . Cannot exist.
- (b,g): the new route has length , equal to , so the shortest distance stays . No path through shortens or either. So this edge can exist.
Answer: (A), (C), (D)
- (b,d): has length , shorter than the shortest path of length . Cannot exist.
- (b,h): has length , shorter than the shortest path of length . Cannot exist.
- (e,g): has length , shorter than the shortest path of length . Cannot exist.
- (b,g): the new route has length , equal to , so the shortest distance stays . No path through shortens or either. So this edge can exist.
Answer: (A), (C), (D)
Consider a directed graph , where and . Suppose the adjacency list of each vertex is in decreasing order of vertex number, and depth-first search (DFS) is performed at vertex 0. The number of vertices that will be discovered after vertex 50 is ___________ (Answer in integer)
Answer: 75
The vertex set is . The edges obey . So from vertex , edges go to and if they exist. Each adjacency list is in decreasing order. So DFS from any vertex tries the "" jump first and the "" jump after that.
DFS starts at . It jumps by every time, because that edge is tried first. The path is . These are all even vertices, and they are discovered first in this order. At DFS is stuck, since no vertex exists. It backtracks and picks up the unvisited "" neighbors on the way back. This discovers the odd vertices in descending order:
So the discovery order is (positions to ), and then (positions to ).
Vertex is the th even vertex discovered. Its position is , since . The vertices discovered after it:
Answer: 75
DFS starts at . It jumps by every time, because that edge is tried first. The path is . These are all even vertices, and they are discovered first in this order. At DFS is stuck, since no vertex exists. It backtracks and picks up the unvisited "" neighbors on the way back. This discovers the odd vertices in descending order:
So the discovery order is (positions to ), and then (positions to ).
Vertex is the th even vertex discovered. Its position is , since . The vertices discovered after it:
Answer: 75
Consider the directed acyclic graph (DAG) below:
Which of the following is/are valid vertex orderings that can be obtained from a topological sort of the DAG?
Which of the following is/are valid vertex orderings that can be obtained from a topological sort of the DAG?
One or more options are correct.
Answer: (B), (D)
A topological order puts every vertex after all the vertices that point to it. The edges are , , , , and . So P and R must come before Q, Q before S and V, S before U, and V before T.
(A) P Q R S T U V: Q comes before R, but R must come before Q. Not valid.
(B) P R Q V S U T: P and R come before Q, Q comes before V and S, V comes before T, S comes before U. Valid.
(C) P Q R S V U T: Q comes before R again. Not valid.
(D) P R Q S V T U: P and R come before Q, Q comes before S and V, S comes before U, V comes before T. Valid.
Answer: (B), (D)
(A) P Q R S T U V: Q comes before R, but R must come before Q. Not valid.
(B) P R Q V S U T: P and R come before Q, Q comes before V and S, V comes before T, S comes before U. Valid.
(C) P Q R S V U T: Q comes before R again. Not valid.
(D) P R Q S V T U: P and R come before Q, Q comes before S and V, S comes before U, V comes before T. Valid.
Answer: (B), (D)
Keep practising
Topics in Programming, Data Structures and Algorithms
Programming in PythonStacks, Queues and Linked ListsTreesHash TablesLinear and Binary SearchSorting and Divide and Conquer
Graph Theory and Graph AlgorithmsYou are here