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:
This section analyzes the properties of Depth First Search (DFS) in graph traversal.
DFS can detect cycles in a graph. It identifies a cycle when it encounters a visited node that is still in the current recursion stack (a back edge).
DFS is effective for finding connected components. By initiating DFS from each unvisited vertex, we can identify all vertices belonging to the same component.
DFS algorithm works correctly on both directed and undirected graphs. The core logic of exploring as deeply as possible applies universally.
DFS does not guarantee the shortest path in unweighted graphs. Breadth First Search (BFS) is the algorithm typically used for finding shortest paths in unweighted graphs because it explores level by level.
Based on the analysis, statements A, B, and C are correct properties of DFS. Statement D is incorrect.
Therefore, the correct combination is A, B, C Only.
Which traversal algorithm is typically implemented using a stack data structure?
Consider the following algorithm someAlgo that takes an undirected graph G as input.
someAlgo (G)
1. Let $v$ be any vertex in G. Run BFS on G starting at $v$. Let $u$ be a vertex in G at maximum distance from $v$ as given by the BFS.
2. Run BFS on G again with $u$ as the starting vertex. Let $z$ be the vertex at maximum distance from $u$ as given by the BFS.
3. Output the distance between $u$ and $z$ in G.
The output of someAlgo (T) for the tree shown in the given figure is ____________ (Answer in integer)

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