Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java code Computing and Algorithms III: Program 1 CS-203 Fall 2017 Assignment Weight: 1.0 Functional Requirements Write a Java program (based on a graph traversal
Java code
Computing and Algorithms III: Program 1 CS-203 Fall 2017 Assignment Weight: 1.0 Functional Requirements Write a Java program (based on a graph traversal algorithm you've learned in this class) that, for a given undirected graph, outputs: (i) vertices of each connected component; (ii) a cycle or a message that the graph is acyclic (if there are more than one cycles in a graph you are required to output just one of them) Your programs should take inputs from a file via the command line with the following structure in the input file. Each line of the input file represents a graph. The first number in a line species the number of vertices in the graph. Then pairs of vertices define the edges. An example of an input file is as follows: It specifies two graphs. The first graph has five vertices (1,2,3,4,5) and four edges. The second graph has four vertices (1,2,3,4) and three edges. Proper output should look (something) like: Graphl Two connected components: 1 2) 3 4 5) Cycle detected: 3- 4-5-3 Graph2: One connected component: (1 234) The graph is acyclic. You must test your programs on a nontrivial input file (with at least 3 graphs and each graph having 7-10 nodes). For the second problem, your test graphs should cover both cyclic and acyclic graphs. Your output should be formatted nicely so that it is easy to read. Your program should use "good style". See the separate handout on style requirements for CS-203 programs. In particular, note that you should describe the algorithms you implement Computing and Algorithms III: Program 1 CS-203 Fall 2017 Assignment Weight: 1.0 Functional Requirements Write a Java program (based on a graph traversal algorithm you've learned in this class) that, for a given undirected graph, outputs: (i) vertices of each connected component; (ii) a cycle or a message that the graph is acyclic (if there are more than one cycles in a graph you are required to output just one of them) Your programs should take inputs from a file via the command line with the following structure in the input file. Each line of the input file represents a graph. The first number in a line species the number of vertices in the graph. Then pairs of vertices define the edges. An example of an input file is as follows: It specifies two graphs. The first graph has five vertices (1,2,3,4,5) and four edges. The second graph has four vertices (1,2,3,4) and three edges. Proper output should look (something) like: Graphl Two connected components: 1 2) 3 4 5) Cycle detected: 3- 4-5-3 Graph2: One connected component: (1 234) The graph is acyclic. You must test your programs on a nontrivial input file (with at least 3 graphs and each graph having 7-10 nodes). For the second problem, your test graphs should cover both cyclic and acyclic graphs. Your output should be formatted nicely so that it is easy to read. Your program should use "good style". See the separate handout on style requirements for CS-203 programs. In particular, note that you should describe the algorithms you implementStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started