Congratulations on implementing the depth-first search algorithm in Python!

To recap this lesson, you gained practice with:

  • Using the TreeNode class 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 None from functions that terminate without reaching a return statement, but it can be a good practice to explicitly return None when other components expect None to 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.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?