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