Question: i need help creating the classes for graphhelptools public class Graphhelptools { / / return an array containing the vertex numbers of an optimal VC

i need help creating the classes for graphhelptools
public class Graphhelptools{
// return an array containing the vertex numbers of an optimal VC.
public static int[] exactVC(Graph inputGraph){
return null;
}
// return (in polynomial time) an array containing the vertex numbers of a VC.
public static int[] inexactVC(Graph inputGraph){
return null;
}
// return an array containing the vertex numbers of an optimal IS.
public static int[] optimalIS(Graph inputGraph){
return null;
}
// return (in polynomial time) an array containing the vertex numbers of a IS.
public static int[] inexactIS(Graph inputGraph){
return null;
}
}
public class Graph {
private int[][] graph; // Must be of the form [vertex][vertexNeighbor1, vertexNeighbor2,...]
public Graph(String fileName){
try (BufferedReader br = new BufferedReader(new FileReader(fileName))){
String line = br.readLine();
if (line.startsWith("numVert")){
graph = new int[Integer.parseInt(line.substring(line.indexOf("")+1))][];
line = br.readLine();
line = br.readLine();
while (line != null){
String[] values = line.split("");
int vertexNum = Integer.parseInt(values[0]);
int numNeighbors = Integer.parseInt(values[1]);
graph[vertexNum]= new int[numNeighbors];
for (int i =0; i < numNeighbors; i++){
graph[vertexNum][i]= Integer.parseInt(values[2+ i]);
}
line = br.readLine();
}
}
} catch (FileNotFoundException ex){
System.out.println("File not found. Try putting file in same filder as src folder.");
} catch (IOException ex){
System.out.println("Exception: "+ ex.toString());
}
}
public int[][] getGraph(){
return graph;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!