Graph Traversal
2 questions · Fundamental Engineering
From the answer group below, select the correct answer to be inserted into blank in the description. Here, the array index starts at 1.
The procedure traverse traces through a vertex of the graph in Figure 1, and outputs all vertex numbers in the graph. One of the vertex numbers of the graph is specified with the argument k. The global 2-dimensional array graph represents the graph in Figure 1. Each element graph[i,j] is equal to 1 if there is an edge between vertices i and j, and 0 otherwise. The array visited stores boolean values, where visited[i] indicates whether vertex i of the graph has been visited or not during the procedure. When the procedure is called as traverse(, the output is in the order blank.
Figure 1 Graph that is handled by the program
Here, the procedure traverse uses a queue represented by the class Queue. Figure 2 provides an explanation of the class Queue.
Figure 2 Explanation of the class Queue
Answer group
From the answer group below, select the correct answer to be inserted into blank in the description. Here, the array indexes start at 1.
The procedure traverse traces through a vertex of the graph shown in the Figure, and outputs all vertex numbers in the graph. The vertex number of the graph is specified with the argument k. The global variable n indicates the number of vertices in the graph. The global array graph represents the graph in the figure. Each element graph[i][j] is equal to 1 if an edge exists between vertices i and j, and it is equal to 0 otherwise. The global array visited stores boolean values, where visited[i] indicates whether vertex i of the graph has been visited during the procedure.
When the procedure is called as traverse(, the output is in the order blank.
Figure Structure of the graph
Answer group