the tough road in learning graph Traversing Graph

Traversing Graph

DFS

DFS is similar with the preorder traverse in tree.

Descirbe

  1. Choose a node as the start node.
  2. Then, visit the adjNode of the start node , regard the one of its adjNodes as a new start node.
  3. repeat the step2, until we find that all the adjNodes of current node has been visisted.
  4. return to the pre node,repeat step2 and step3.
  5. Eventually, if there are still some modes remained,add them to the tail of the sequence.

implementation(ALGraph)

  1. Use a for-loop to initialize the Visited Array.
  2. Use a for-loop,judging the visited property at first. If the node has not been visited yet,call the DFS
  3. DFS:
    1. assign the visited property with true.
    2. visit operation
    3. FirstAdhVex
    4. NextAdjVex

      Firstadj

BFS

find children recursively, assisted