Q67.Marks: +2.0UGC NET Paper 2: Computer Science 2nd January 2026 Shift 1
Which of the following statements about DFS are correct?
A. It can detect cycles in a graph
B. It can be used to find connected components.
C. It works for both directed and undirected graph.
D. Guarantees shortest path in unweighted graphs.
Choose the correct answer from the options given below:
1.A, B, C Only✓ Correct
2.A, B, C, D
3.C, D Only
4.B, C Only
Solution
The correct answer is A, B, C Only.
Key Points
Depth First Search (DFS) is a graph traversal algorithm that explores as far as possible along each branch before backtracking.
It can be used to detect cycles in a graph by checking if there are back edges during traversal.
DFS helps in finding connected components in an undirected graph by initiating DFS from unvisited nodes.
DFS works for both directed and undirected graphs because it explores vertices systematically.
DFS does not guarantee shortest path in unweighted graphs because it prioritizes depth over breadth.
Additional Information
Applications of DFS:
Cycle Detection: DFS identifies cycles by tracking visited nodes and detecting back edges.
Topological Sorting: DFS is used in directed acyclic graphs to determine the linear ordering of vertices.
Pathfinding: DFS can be used to find a path between two vertices, though it does not guarantee the shortest path.
Connected Components: DFS helps in grouping connected nodes in undirected graphs.
Maze Solving: DFS explores all possible paths in a maze until a solution is found.
DFS Algorithm Overview:
Start from a source node, mark it as visited, and explore its neighbors recursively.
Use a stack (explicit or implicit through recursion) to keep track of nodes to visit.
Backtrack when all neighbors of a node are visited.
Repeat for all unvisited nodes to ensure complete graph traversal.
DFS vs BFS:
DFS: Prioritizes depth-first exploration, uses a stack, and may not find the shortest path.
BFS: Prioritizes breadth-first exploration, uses a queue, and guarantees the shortest path in unweighted graphs.