Recall & Review
beginner
What is Depth First Search (DFS) in graph traversal?
DFS is a method to explore a graph by starting at a node and exploring as far as possible along each branch before backtracking.
Click to reveal answer
beginner
In DFS, what data structure is commonly used to keep track of nodes to visit next?
A stack is used to keep track of nodes to visit next, either explicitly or via recursion call stack.
Click to reveal answer
beginner
Why do we mark nodes as visited in DFS?
Marking nodes as visited prevents revisiting the same node, avoiding infinite loops and repeated work.
Click to reveal answer
intermediate
What is the order of node visits in DFS on a graph with nodes 1 connected to 2 and 3, and 2 connected to 4?
Starting at 1, DFS visits 1 → 2 → 4 → 3 (assuming neighbors are visited in numerical order).
Click to reveal answer
intermediate
What is the time complexity of DFS on a graph with V vertices and E edges?
The time complexity is O(V + E) because each vertex and edge is visited once.
Click to reveal answer
Which data structure is naturally used by recursive DFS?
✗ Incorrect
Recursive DFS uses the call stack to keep track of nodes, which behaves like a stack.
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.
In DFS, when do you backtrack?
✗ Incorrect
Backtracking happens when the current node has no unvisited neighbors left to explore.
What is the first node visited in DFS starting from node 1 in a graph?
✗ Incorrect
DFS starts at the given start node, here node 1.
Which of these is NOT a use case of DFS?
✗ Incorrect
Shortest path in unweighted graphs is better found by BFS, not DFS.
Explain how DFS explores a graph starting from a node. Include how it uses the stack and visited nodes.
Think about going deep first before going wide.
You got /5 concepts.
Describe the time complexity of DFS and why it is O(V + E) for a graph with V vertices and E edges.
Consider how many times nodes and edges are processed.
You got /4 concepts.