Consider a graph with nodes labeled A, B, C, D, and E. Starting a Depth-First Search (DFS) from node A, which of the following sequences correctly represents a possible order of node visits?
Remember that DFS explores as far as possible along each branch before backtracking.
DFS starts at A, visits B, then explores B's neighbors deeply before backtracking. The sequence A, B, D, E, C is a valid DFS traversal order.
Which of the following statements correctly describes how DFS can be used to detect a cycle in a directed graph?
Think about how recursion stack helps track the current path in DFS.
DFS uses a recursion stack to keep track of nodes in the current path. Revisiting a node in this stack means a cycle.
Given a graph with V vertices and E edges, what is the time complexity of performing a DFS traversal on the graph?
Consider how many times each vertex and edge is visited during DFS.
DFS visits each vertex once and explores each edge once, resulting in O(V + E) time complexity.
Which statement best compares DFS and BFS when used to find a path between two nodes in an unweighted graph?
Think about how BFS explores neighbors level by level.
BFS explores nodes in layers, guaranteeing the shortest path in unweighted graphs. DFS explores deeply and may find longer paths.
Why is DFS suitable for performing a topological sort on a Directed Acyclic Graph (DAG)?
Consider the order in which nodes finish during DFS traversal.
DFS explores all descendants before the node, so recording nodes in reverse finishing order produces a valid topological sort.