Algorithm · SoFi · Medium
Requirements Write Collection reachableNodes(Vertex start) for a directed graph in which each vertex can provide its outbound neighbors. Produce the collection of all vertices that can be reached from start, with start included in that collection. Graph cycles must not cause the traversal to process the same vertices forever. You should be ready to use either a recursive depth-first search or an iterative traversal driven by an explicit stack. Follow-up: contrast DFS with…
Checking your access…