YCP Logo Lecture 17: Depth-First Search (DFS)

BFS is used to find the shortest paths (by number of edges) to every reachable vertex from a given one. Alternatively we may wish to follow a particular path to maximal depth and then backtrack to follow other paths in a depth-first fashion (DFS) creating a forest of depth-first trees. DFS does not give shortest paths but is useful as part of other algorithms.