A depth-first path-traversal uses a stack in order to remember directories as it scans. Initially, a directory is supplied which is scanned for directories in order to push them onto the stack. On every iteration, a directory is popped off the stack and similarly scanned in order to push any newly found directories. The algorithm terminates when the stack is empty.
where is the number of edges and is the number of vertices.