Experiment Name: Design and implementation of graph traversal algorithm
Second, the purpose of the experiment:
1. Grasp the algorithm of depth-first traversal of graphs.
2. Grasp the breadth-first traversal algorithm of graphs.
3. Experiment Chapter: Algorithm design and analysis fourth chapter
Third, the experimental content. Experimental problems and program running results
The first part breadth-first traversal algorithm
1. Analyze graph class and draw graph object data structure after initialization of graph class.
2. Analyze the BFS function and draw a flowchart.
3. The above procedure int data[7][7]={{1,-1,-1,-1,-1,-1,-1},
{6, 3, 2,-1,-1,-1,-1},
{0,-1,-1,-1,-1,-1,-1},
{2, 0,-1,-1,-1,-1,-1},
{6, 5,-1,-1,-1,-1,-1},
{1,-1,-1,-1,-1,-1,-1},
{5, 3,-1,-1,-1,-1,-1}};
is the input to the textbook figure 4-1, and the order of breadth precedence starting from 0 is:
4. If the traversal starts at node 4, what is the order of breadth precedence?
5. Analyze when the graph class object, at the time of input at 1, the breadth precedence starting from 0. Design data[][] Data for input, and gives the sequence of traversal in the case of this type of input.
6. Rewrite the program, output the parent array value, and draw the breadth-first deep forest of Figure 1 according to the parent.
The second part depth-first traversal algorithm
- Analyze the DFS program and give the DFS flowchart:
- The DFS traversal order for Figure 4-1 is:
- When the DFS traversal of Figure 1, what is the traversal order, based on the parent value, infer what depth-first deep forest is.
- Design a diagram yourself and calculate the depth traversal and breadth traversal sequence through the program.
Iv. Summary of the experiment and experience:
Design and implementation of ERGODIC algorithm for experiment four graph