unmark all for each if is unmarked end if end for | mark for each if is unmarked end if end for return |
Suppose that the input directed graph is a directed acyclic graph (DAG).
For an edge , which of the following options will NEVER be correct?
["B","D"]
Step-by-Step Solution
Key idea: This is a "DFS timestamp and DAG properties" question, recognisable because it asks which timestamp relationships are impossible for an edge in a Directed Acyclic Graph.
Step 1: Understand the Parenthesis Theorem.
For any two vertices and in a DFS traversal, their discovery/finish intervals and must be either completely disjoint or perfectly nested. They can never partially overlap.
Step 2: Evaluate Option D.
represents partially overlapping intervals. This violates the Parenthesis Theorem and is impossible in ANY DFS traversal, regardless of whether the graph is a DAG. Thus, Option D will NEVER be correct.
Step 3: Evaluate Option B.
represents perfectly nested intervals where is an ancestor of . This means the edge goes from a descendant to an ancestor, which is the definition of a back edge. A back edge implies the existence of a cycle. Since the input graph is a DAG (Directed Acyclic Graph), it cannot contain any cycles, and therefore cannot contain any back edges. Thus, Option B will NEVER be correct.
Step 4: Evaluate Options A and C.
Option A () represents nested intervals where is an ancestor of . This corresponds to a tree edge or forward edge, which are perfectly valid in a DAG.
Option C () represents disjoint intervals where is completely finished before is discovered. This corresponds to a cross edge, which is also valid in a DAG.
Answer: B, D