In this Java assignment you are to implement a graph G(V, E) searching algorithm that will take two source nodes and outputs all nodes that are reachable from both of these sources. Your program has to read an input file with the following structure:

1. integer number V that specifies how many nodes in the graph

2. a space delimited matrix of V rows and V columns that defines the graph's edges

3. integer number S1 is source 1 for the graph search (the node labels start with 0 to V-1)

4. integer number S2 is source 2 for the graph search (the node labels start with 0 to V-1)

Input File Example:

4
0 0 1 1
1 1 0 0
1 0 1 0
1 0 1 0
3
0

You program's output that would run search on the above graph would be:

0,2,3

Note:

You can use whatever algorithm we went over in the class to solve this problem.

Things to look out for:

cycles are always a problem in graphs

implement a simple cycle check to make sure you are not stuck in an endless loop

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.