Chapter 41: Depth-First Search Challenges

Challenge 1

For each of the following two examples, which traversal (depth-first or breadth-first) is better for discovering if a path exists between the two nodes? Explain why.

Path from A to F. Path from A to G.

DFS: 找深 - Path from A to F

BFS: 找寬 - Path from A to G

Challenge 2

In this chapter, you went over an iterative implementation of depth-first search. Now write a recursive implementation.

Challenge 3

Add a method to Graph to detect if a directed graph has a cycle

Last updated