(C,8,2) (D,6,1) (E,9,4) (F,2,-1) (G,7,3) (J,3,9) (H,10,8) (L,5,10) (1,1,7) (Κ,-1,5) (Μ,4,6)
Question 3: (2 marks)
In this question you should complete some methods in Graph.java file.
The class Graph is the implementation of a graph. The following methods should be completed:
void f1() - Perform breadth-first traversal (to the file f1.txt) from the vertex i=3 (the vertex D))but display 5 vertices with their degrees from the 3rd vertex to the 7th vertex only. Hint: copy breadth(...) to breadth2(...) and modify the latter one. The array int deg[] already declared in the class Graph. You should calculate d[i] = degree of the vertex i, i=0,1,..,n-1 and use the function fvisitDeg(...) to display a vertice with degree to file. Content of the output file f1.txt must be:
DABGCEFHI
B(3) G(1) C(3) E(2) F(1)
void f2() - Apply the Dijkstra's shortest path algorithm to find (1) the shortest path from vertext 0 (A) to vertex 6 (G), then (2) from vertex 1 (B) to vertex 5 (F). Write 3 lines to the file f2.txt: line 1 contains the first 3 vertices selected into the set S in (1), line 2 contains the 1st, 3rd, last vertices in shortest path and shortest distance in (1), line 3 contains vertices in shortest path (2).(Note that in the weighted matrix, the value 99 is considered as infinity). Output in the file f2.txt must be the following:
ACG 29
BCEDF
Zoom
Close
+ 100%
AIB