Depth First Search is a method of traversing graphs and trees which travels to the end of each branch first.

Depth First Search visits each node exactly once, so if you keep track of the nodes you have visited you can detect cycles.


Example

Under depth first search the correct order to traverse this graph (in the case of multiple choice taking the first alphabetically) is: A → B → D → F → E → C → G

Example

Under depth first search the correct order to traverse this graph (in the case of multiple choice taking the first alphabetically) is: a → b → e → h → i → g → f → j → d → c