We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Depth First Search (DFS)

Depth-first search (DFS) is just another algorithm to traverse a graph - kind of like breadth first search. It starts at a root node (some arbitrary node on the graph) and explores as far as possible along each branch before backtracking and starting down the next branch.

The provided image depicting Depth First Search (DFS) is illustrative and not directly related to the specific code assignment in this lesson.

Try stepping through a small graph:

Interactive example available with JavaScript enabled.

Assignment

The LockedIn executives want us to add a depth-first search feature to geographic search.

Complete the depth_first_search and depth_first_search_r methods. The depth_first_search_r method is a recursive helper method for depth_first_search.

      • If the neighboring vertex hasn't been visited yet, visit it by recursively calling depth_first_search_r with the neighboring vertex