Data Structures & AlgorithmsHardProduct-company MCQ pattern

How many of these statements about DFS are correct? (i) In DFS of an undirected graph, every non-tree edge is a back edge (there are no cross edges). (ii) A directed graph has a cycle if and only if its DFS finds a back edge. (iii) Listing vertices in decreasing order of DFS finish time gives a topological order of a DAG. (iv) DFS on an adjacency matrix runs in O(V + E).

  1. A. Only one
  2. B. Only two
  3. C. Only three
  4. D. All four

Correct answer: C. Only three

(i), (ii) and (iii) are true. (iv) is false: with an adjacency matrix every vertex scans a whole row of V entries, so DFS takes O(V²); O(V + E) needs adjacency lists.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic