Log in from a computer to take this course

You'll need to log in from a computer to start Learn Data Structures and Algorithms with Python. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Time to handle our base case!

If the current vertex value is the same as the value we are looking for, then:

  • we’re done searching
  • we can return our path (the visited list)
# what you've built out so far: def dfs(graph, current_vertex, target_value, visited): set visited to empty list if not yet set add current_vertex to visited # base case: if current_vertex is equal to target_value: return visited list

Instructions

1.

Create an if statement that returns visited when current_vertex is the same as target_value.

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?