Question: A directed graph can be represented with an adjacency matrix containing 1s and 0s. The columns represent the destination nodes and the rows represent the

A directed graph can be represented with an adjacency matrix containing 1s and 0s. The columns represent the destination nodes and the rows represent the source nodes. For example, in the adjacency matrix below: 3 0 1 1 1 0 1 1 1 0

The graph has 3 nodes (indicated by the 3 at the top) and one can deduce all possible paths one can take from the directed edges. All the possible paths are below:

Path from 1 to 1 1 -> 2 -> 1 1 -> 2 -> 3 -> 1 1 -> 3 -> 1 1 -> 3 -> 2 -> 1

Path from 1 to 2 1 -> 2 1 -> 3 -> 2

Path from 1 to 3 1 -> 2 -> 3 1 -> 3

Path from 2 to 1 2 -> 1 2 -> 3 -> 1

Path from 2 to 2 2 -> 1 -> 2 2 -> 1 -> 3 -> 2 2 -> 3 -> 1 -> 2 2 -> 3 -> 2

Path from 2 to 3 2 -> 1 -> 3 2 -> 3

Path from 3 to 1 3 -> 1 3 -> 2 -> 1

Path from 3 to 2 3 -> 1 -> 2 3 -> 2

Path from 3 to 3 3 -> 1 -> 2 -> 3 3 -> 1 -> 3 3 -> 2 -> 1 -> 3 3 -> 2 -> 3

Write a program in Java to read in the number of nodes in the graph and the corresponding adjacency matrix, one row at a time from the input file (see below) and convert it into an adjacency list (example: https://en.wikipedia.org/wiki/Adjacency_list). The program can use recursion or iteration to find and list all possible non-looping paths between all possible pairs of nodes. It is ok if the start and end nodes are the same but otherwise the nodes should not repeat within the path. If no path exists for a particular pair of nodes then print 'No Path Found'. Check out all possible paths in each graph. Put all results into an output file. Copy the adjacency matrix to the output file. Do not use LinkedList, ArrayList, Java.util*, etc.

Use Java 7 or 8 (JDK 1.7 or 1.8) to take an input file, read and process the data in a specific way (outlined above) and put results in an output file. Use of standard libraries is restricted to standard I/O calls and standard math functions, etc. In other words, you can't use LinkedList. Use named files to handle I/O. No hardcoded file names. Enter file names as command line prompts. Do NOT use GUI/console input of data. Output files must: Contain the input as well as contain answers to the required input. Be user friendly with additional labels, lines, and white space. Have statistical information as needed.

Sample input: 4 0 1 1 0 1 1 1 1 1 0 0 0 1 1 0 1 6 0 1 0 1 1 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 1 3 0 1 1 1 0 1 1 1 0

A directed graph can be represented with an adjacency matrix containing 1s

input Notepad File Edit Format View Help 0 1 1 1000 1 1 01 0 1 0 1 1 0 1 001 1 0 00 1 00 1 00001 0 1 00 0 o 0 0 01 001 0 1 1 1 01 1 1 0

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 Databases Questions!