Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP PLEASE JAVA PROGRAM Make a program on a graph traversal algorithm either Depth-first search (DFS) or Breadth-first search (BFS) for a given undirected

JAVA HELP PLEASE

JAVA PROGRAM Make a program on a graph traversal algorithm either Depth-first search (DFS) or Breadth-first search (BFS) 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).

The 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 the rest of the numbers in the brackets represent the edages.

THIS IS AN EXAMPLE OF AN INPUT FILE: 5 (1,2) (3,4) (3,5) (4,5) 4 (1,2) (2,3) (1,4)

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.

OUTPUT SHOULD LOOK LIKE: Graph1: Two connected components: {1 2} {3 4 5} Cycle detected: 3 - 4 - 5 - 3

Graph2: One connected component: {1 2 3 4} 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. EXTRA HELP: Connected component: in graph theory, a connected component (or just component) of an undirected graph is a subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the supergraph. PLEASE HELP I NEED IT ASAP

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Show algebraically that it is possible to construct an angle of 30.

Answered: 1 week ago