Q82.Marks: +2.0UGC NET Paper 2: Computer Science 2nd January 2026 Shift 1
Given below are two statements: one is labelled as Assertion A and the other is labelled as Reason R
Assertion A: Depth first search can be used to perform a topological sort of a directed acyclic graph.
Reason R: A topological sort a directed acyclic graph G (V, E) is a linear ordering of its vertices such that if G contain an edge (u, v) then u appears before v in the ordering.
In the light of the above statements, choose the most appropriate answer from the options given below
1.Both A and R are correct and R is the correct explanation of A✓ Correct
2. Both A and R are correct but R is NOT the correct explanation of A
3.A is correct but R is not correct
4.A is not correct but R is correct
Solution
The correct answer is Both A and R are correct and R is the correct explanation of A.
Key Points
Depth First Search (DFS) is an algorithm that can be used to perform a topological sort of a Directed Acyclic Graph (DAG).
Topological sorting is a linear ordering of vertices in a directed graph such that for every directed edge (u, v), vertex u comes before vertex v in the ordering.
DFS traverses the graph and ensures that all dependencies (edges) are considered before adding a vertex to the sort order, which directly aligns with the requirements of topological sorting.
The Reason (R) provided in the question correctly defines what a topological sort is, and the Assertion (A) is correct because DFS can be used to achieve this sorting in a DAG.
Additional Information
Steps for Topological Sorting Using DFS:
Perform a Depth First Search (DFS) traversal on the graph.
While visiting each vertex, recursively visit its adjacent vertices first.
Once all adjacent vertices are visited, add the current vertex to a stack.
After the DFS is complete, the stack contains the vertices in topological order.
Applications of Topological Sorting:
Task scheduling problems where certain tasks must be completed before others.
Dependency resolution in package management systems.
Compiler optimizations for determining the order of execution of code modules.
Important Points About Topological Sorting:
It is only valid for Directed Acyclic Graphs (DAGs). If a cycle exists in the graph, topological sorting is not possible.
Multiple valid topological orders can exist for the same graph, depending on the order of traversal.