Recall & Review
beginner Click to reveal answer
What is the main idea behind Depth First Search (DFS) on a graph?
DFS explores as far as possible along each branch before backtracking. It goes deep into one path before trying another.
beginner Click to reveal answer
In DFS, how do we keep track of which nodes have been visited?
We use a 'visited' set or array to mark nodes that have already been explored to avoid revisiting them.
intermediate Click to reveal answer
What data structure is commonly used to implement DFS iteratively?
A stack is used to keep track of nodes to visit next, following the last-in, first-out order.
intermediate Click to reveal answer
How does DFS differ from Breadth First Search (BFS)?
DFS goes deep into one path before backtracking, while BFS explores all neighbors at the current depth before going deeper.
beginner Click to reveal answer
What is a common use case for DFS in graphs?
DFS is used for tasks like detecting cycles, finding connected components, and pathfinding in mazes.
What does DFS use to remember which nodes to visit next in its recursive form?
✗ Incorrect
In recursive DFS, the system call stack keeps track of nodes to visit next.
Which of the following is true about DFS?
✗ Incorrect
DFS explores as deep as possible along each branch before backtracking.
What is the time complexity of DFS on a graph with V vertices and E edges?
✗ Incorrect
DFS visits every vertex and edge once, so time complexity is O(V + E).
Which data structure is NOT typically used in DFS implementations?
✗ Incorrect
Queues are used in BFS, not DFS.
What happens if you do not mark nodes as visited in DFS?
✗ Incorrect
Without marking visited nodes, DFS can revisit nodes and enter infinite loops in cyclic graphs.
Explain how DFS explores a graph starting from a given node.
Think about going deep into one path before trying others.
You got /5 concepts.
Describe how you would implement DFS iteratively using a stack.
Use a stack to remember where to go next instead of recursion.
You got /5 concepts.
