create a code in JAVA that takes arguments to do a bfs(breadth first search) or a dfs( depth first search) using a txt file as the graph input.
I have made most of the main function as well as a nose function I just need the bfs and dfs functions to work here's what I have so far, the comments that start with TODO are the parts that I need to finish
Main.java
import java.io.*;
import java.util;
ArrayList; import java.util.Iterator;
import java.util.List;
public class Main {
//class variables
private static boolean extendedOn;
public static String [] arr;
public static List<Node> nodeList;
public static Node firstNode;
public static int vertices;
//main method
public static void main(String[]args){
//the int for the arguments
int argument = 0;
int destination;
extendedOn = false;
boolean isDfs = false;
//checks to make sure that the user specified the destination
if(args[argument].equals("-dest")){
argument++;
try { destination = Integer.parseInt(args[argument]); argument++;
}catch (Exception e{
System.out.println("Wrong Argument, needs an integer");
System.exit(0); } }
else{ System.out.println("Please specify the destination using
-dest");
System.exit(0); }
//if the first arg is -e if(args[argument].equals("-e")){
argument++; extendedOn = true; }
//if args is dfs if(args[argument].equals("-dfs")){ argument++;
isDfs = true; }
//if the args is -bfs else if(args[argument].equals("-bfs")){
argument++; isDfs = false; }
else{
System.out.println("Requires a Search Argument"); System.exit(0);
}
//the argument that gets the file
File file = new File( args[argument] ); instantiateList(file);
//gets the initial time Long timeStart =
System.currentTimeMillis();
//figures out whether to do dfs or bfs
if(isDfs){ DFS(firstNode); }
else{ BFS(); }
//gets the endingTime Long timeEnd = System.currentTimeMillis();
System.out.println("\nTime Taken: " + (timeEnd - timeStart)); }
//method that populates the node list with how many
vertices there are
private static void instantiateNodes(){
for(int y = 1; y <= vertices; y++){
nodeList.add(new Node(y)); }
firstNode = nodeList.get(0); }
//method to instantiate the List
public static void instantiateList(File file){
vertices = 0;
//String [] arr; //= new String[0];
//reads the file
try (BufferedReader br = new BufferedReader(new FileReader(file)))
{
//gets the vertices then creates the array which the buffered
reader will put the values into
vertices = Integer.parseInt(br.readLine());
arr = new String[vertices];
int counter = 0;
//puts the values in String line = null;
while ((line = br.readLine()) != null)
{ arr[counter++] = line; } }
catch (FileNotFoundException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
//prints out the vertices and initializes the nodeList
System.out.println("\nVertices: " + vertices);
nodeList = new ArrayList<>(); instantiateNodes();
//for loop
for(int x = 0; x < vertices; x++){
//populates a list with the vertexes
String line = arr[x];
List adjacentVertexes = new ArrayList();
//while the line is not empty put it in the list
while(!line.isEmpty())
{ String vertex;
//if there are multiple vertexes
if(line.contains(" "))
{ vertex = line.substring(0, line.indexOf(" "));
//gets the node from the node list and adds it to the Node's
adjacency List adjacentVertexes.add(nodeList.get(
(Integer.parseInt(vertex)) - 1 )); }
//if there is only one vertex left else{
adjacentVertexes.add(nodeList.get( (Integer.parseInt(line)) - 1
));
line = ""; break; } //changes the line to the next vertex line =
line.substring(line.indexOf(" ")+1); }
//creates the node and initializes it
Node newNode = nodeList.get(
((Node)adjacentVertexes.get(0)).getVertex() - 1 );
//removes the name of the vertex and sets it's list
adjacentVertexes.remove(0);
newNode.setList(adjacentVertexes);
//adds the newNode to the list of Nodes nodeList.add(newNode); }
}
//TODO method for the BFS
public static void BFS(){ System.out.println("BFS:"); }
//TODO method for the DFS
public static void DFS(){ System.out.println("DFS:"); } } }
Node.java
import java.util.List;
public class Node {
//variable for if the node has been visited before
private boolean hasBeenSearched;
private List<Node> adjacency;
private int vertex;
public int searched;
public Node(int v){
vertex = v;
hasBeenSearched = false; }
//gets the vertex of the node
public int getVertex(){
return vertex; }
//sets the variables for if the node has already been searched
public void setSearch(boolean search){
hasBeenSearched =
search; }
//gets the varaible for the search of the node
public boolean getSearch(){
return hasBeenSearched; }
//method used to set the list full of nodes
public void setList(List<Node> nodeList){
adjacency = nodeList;
}
//method used to get the Node from the list
public Node getNode(int index){
return adjacency.get(index); }
//method used to get the size of the adjacency list
public int getSize(){
return adjacency.size();
} }
In: Computer Science
A round-robin tournament involving n plays is modeled with digraph D where, for every two distinct vertices (players) u and v, either (u,v) is an edge (player u defeats player v) or (v,u) is an edge (player v defeats play u). Prove that if D is acyclic, i.e., no directed cycles, then there always exists a player who has defeated everyone (out-degree is n – 1) and a player who has lost to everyone (in-degree is n – 1).
In: Advanced Math
(3) Let V be a vector space over a field F. Suppose that a ? F, v ? V and av = 0. Prove that a = 0 or v = 0.
(4) Prove that for any field F, F is a vector space over F.
(5) Prove that the set V = {a0 + a1x + a2x 2 + a3x 3 | a0, a1, a2, a3 ? R} of polynomials of degree ? 3 is a vector space over R (with respect to the usual addition and scalar multiplication of polynomials).
In: Math
In: Computer Science
Let u and v be orthogonal vectors in R3 and let w = 3u + 6v. Suppose that ||u|| = 5 and ||v|| = 4. Find the cosine of the angle between w and v.
In: Advanced Math
For a comparison of two study guides for a mathematics course, 14 student volunteers were found. They were randomly assigned, 7 to study guide A, and 7 to study guide B. Following a two-day period of independent study, the students were examined on the material. The students received the following scores (out of 100):
Study Guide A: 95 96 97 80 92 97 95
Study Guide B: 72 73 80 69 78 74 73
Use a permutation test to test the null hypothesis that the distributions of scores are the same for each study guide, against the two-sided alternative that the distributions are different.
1. How many possible ways are there to randomly allocate the 14 students into two groups of 7 students? [2 pt(s)]
2. Compute the difference in sample means, A(bar) - B(bar) as the test statistic. [1 pt(s)]
3. How many arrangements of the data would lead to an absolute value of the computed test statistic as great or greater than the absolute value of the test statistic you calculated in the previous question? Note that you don't have to list all possible arrangements in order to answer this. Examine the data carefully and use the trick that was shown in class (also on pages 8-9 of the typed notes) for the permutation problem. [5 pt(s)]
4. Suppose that after examining all the possible arrangements, it is found that the absolute value of the difference in means for 16 of the arrangements (including the real one that you observed) are greater than or equal to the absolute value of the computed test statistic. What is the two-sided p-value for the permutation test? Use at least 5 digits to the right of the decimal. [2 pt(s)]
In: Statistics and Probability
X is an independent standard uniform random variable X ∼ Uniform(0, 1)
Y is an independent standard uniform random variable Y ∼ Uniform(0, 1)
U = min(X, Y )
V = max(X, Y )
Find the correlation coefficient of V and U , ρ(U, V) = Correlation(U, V).
In: Statistics and Probability
What is Cramer's V for each of the following values for the chi-square test for independence? (Round your answers to two decimal places.)
(a) X2 = 3.95, n = 50, dfsmaller = 1 V =
(b) X2 = 8.81, n = 110, dfsmaller = 2 V =
(c) X2 = 11.62, n = 180, dfsmaller = 3 V =
In: Statistics and Probability
Directions: Solve the question 1st, then place the answer in the appropriate blank.
In Drosophila, cinnabar eye color (c), vestigal wings (v) and plexus wing veins (p) are all autosomal recessive mutations linked on chromosome 2. A true-breeding cinnabar, vestigal winged female was crossed to a true-breeding plexus vein male. The wild type F1 females were mated to a plexus, vestigal winged male with cinnabar eyes and the following progeny were obtained.
|
Cinnabar |
Vestigial |
Plexus |
total |
|
c |
v |
p |
45 |
|
c+ |
v+ |
p+ |
52 |
|
c |
v |
p+ |
384 |
|
c+ |
v+ |
p |
375 |
|
c |
v+ |
p |
6 |
|
c+ |
v |
p+ |
9 |
|
c |
v+ |
p+ |
64 |
|
c+ |
v |
p |
65 |
|
total |
1000 |
Please solve the problem and complete the following fill-in the blank questions.
a. What is the gene order on chromosome 2?
b. What is the distance between cinnabar eyes and vestigal wings?
c. What is the distance between vestigal wings and plexus veins?
d. What is the distance between cinnabar eyes and plexus veins?
e. What is the interference in this cross?
In: Biology
In: Nursing