Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 985 Bytes

README.md

File metadata and controls

21 lines (17 loc) · 985 Bytes

Mark visited 1

Starting from a given node, traverse all the reachable nodes using dpth first heuristic and each node is only visited once.
Mark the node as visited when first time entering the node.

time: O(V + E) every node will be visited once O(V) and every edge will only be generated once.
space: O(V)

Mark visited 2

Mark visited after all its descendants.
We need additional state "visiting" to deal with a special marker of the nodes on the current dfs path to avoid duplicately visiting nodes.
Mark the nodes as visitin when first time entering the node, Mark the node as visited when all the neighbors are visited.

time: O(E + V)
space: O(V)

Mark visited 3

Care about the pathes, instead of the vertex is reachable in this case.
Find all paths from the start node, on the path there is no duplicate vertices.
only mark for the nodes on the current dfs path, avoiding cycle on the dfs path

time: O(branch^V)
space: O(V)