Congratulations on implementing the depth-first search algorithm in Python!
To recap this lesson, you gained practice with:
- Using the
TreeNodeclass to store a tree data structure.
- Implementing a recursive method that searches for a path to a node with a specified value using the recursive paradigm often called “divide and conquer.”
- Default function arguments in Python.
- Tuples, which are immutable lists, can be a convenient choice over lists for recursive methods like this.
- Python will implicitly return
Nonefrom functions that terminate without reaching a
returnstatement, but it can be a good practice to explicitly return
Nonewhen other components expect
Noneto be returned sometimes.
Feel free to experiment with your code here. Try building trees of various shapes and sizes and search for items in various positions.