Recall & Review
beginner Click to reveal answer
What does DFS stand for in graph traversal?
DFS stands for Depth First Search, a method to explore graph nodes by going as deep as possible before backtracking.
beginner Click to reveal answer
In DFS, what data structure is commonly used to keep track of nodes to visit next?
A stack is used in DFS to keep track of nodes to visit next, either explicitly or via recursion call stack.
beginner Click to reveal answer
Why do we mark nodes as visited in DFS?
Marking nodes as visited prevents revisiting the same node, avoiding infinite loops and repeated work.
intermediate Click to reveal answer
What is the order of node visits in DFS on a graph with nodes 1 connected to 2 and 3, starting at 1?
Starting at node 1, DFS visits node 1, then goes deep to node 2, then backtracks and visits node 3.
intermediate Click to reveal answer
How does DFS differ from BFS in graph traversal?
DFS explores as far as possible along each branch before backtracking, while BFS explores neighbors level by level.
What data structure does DFS use implicitly when implemented recursively?
✗ Incorrect
DFS uses the call stack implicitly when implemented recursively, which behaves like a stack.
Which of these is NOT a typical step in DFS?
✗ Incorrect
DFS does not add neighbors to a queue; it uses a stack or recursion to explore deeply.
What happens if you do not mark nodes as visited in DFS on a graph with cycles?
✗ Incorrect
Without marking visited nodes, DFS can revisit nodes endlessly in cycles, causing infinite loops.
Starting DFS at node 1 in a graph 1->2, 1->3, 2->4, which node is visited last?
✗ Incorrect
DFS visits 1, then 2, then 4, then backtracks and visits 3 last.
Which traversal method is better for finding the shortest path in an unweighted graph?
✗ Incorrect
BFS finds the shortest path in unweighted graphs by exploring neighbors level by level.
Explain how DFS explores nodes in a graph and why it uses a stack or recursion.
Think about going down one path fully before trying others.
You got /3 concepts.
Describe the difference between DFS and BFS in terms of node visiting order and typical use cases.
Compare how each method moves through the graph.
You got /5 concepts.
