Depth first search, or DFS is a core algorithm generally used to traverse graphs.

Performing depth first search on a graph results in the visited edges and nodes looking like a spanning tree.

Time complexity

The time complexity of using depth-first search using an adjacency matrix is

But when maximally efficient using an adjacency list, the time complexity is:

Where V and E are the number of vertices and edges respectively.