Traversing Graph
DFS
DFS is similar with the preorder traverse in tree.
Descirbe
- Choose a node as the start node.
- Then, visit the adjNode of the start node , regard the one of its adjNodes as a new start node.
- repeat the step2, until we find that all the adjNodes of current node has been visisted.
- return to the pre node,repeat step2 and step3.
- Eventually, if there are still some modes remained,add them to the tail of the sequence.
implementation(ALGraph)
- Use a for-loop to initialize the Visited Array.
- Use a for-loop,judging the visited property at first. If the node has not been visited yet,call the DFS
- DFS:
BFS
find children recursively, assisted
近期评论