Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

helppp coding this in java pleaseee The goal of this assignment is to practice w

ID: 3571514 • Letter: H

Question

helppp coding this in java pleaseee

The goal of this assignment is to practice working with directed graphs.

You are to write a program to perform a modified topological sort on a directed graph. A topological sort of a directed graph G is an ordering v1, …, vn of the vertices of G such that for every pair of vertices vi and vj, if there is a path from vi to vj then i < j. This implies that G has no directed cycles.

Suppose that we modify this problem to handle cycles in the following way: if vertices are part of the same directed cycle then they can all be taken at the same time. However, vertices should only be taken at the same time if necessary. Given this modification, we might consider the ordering as being an ordering between sets.

As an example, consider the problem of finding a sequence of courses such that whenever a course is taken, all of its prerequisites are satisfied: our modification allows for corequisites, i.e. courses that must be taken concurrently.

Example:

Consider the graph represented by the following adjacency matrix:

101 102 120 125 130 230

101 0 1 1 0 0 0

102 1 0 0 1 0 0

120 0 0 0 1 0 0

125 0 0 0 0 1 0

130 0 0 1 0 0 1

230 0 0 0 0 0 0

This graph contains two directed cycles.

A valid topological ordering would be as follows:

{101, 102}, {120, 125, 130}, {230}

This indicates that first 101 and 102 should be taken concurrently, followed by 120, 125 and 130 all concurrently, and then finally 230. Note that any permutation of the values within each set is also a valid solution; consider, for example, {102, 101}, {120, 125, 130}, {230}.

Input: Your program should read from a file; this file has the following format:

An integer value n, indicating that we have a graph with n vertices.

A list of n integers representing vertex labels

A nxn binary array representing the adjacency matrix of the graph in row-major order.

Output:

* A modified topological sort of the graph, written in the format used in the example above:

* each set of vertices taken at the same time are enclosed within curly brackets {} and separated by commas within those brackets, and

* each of the sets should also be separated by commas.

Hint: Ensure that your program is able to handle the situation in which the same vertex is part of more than 1 directed cycle.

Using txt file

Explanation / Answer

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public category TopologicalSortGraph kind implementation takes the instance graph in
* Version 1: implementation with unweighted
* Assumption : Graph is directed
*/
TopologicalSortGraph Graph = new TopologicalSortGraph();
//public LinkedList&lt;Node&gt; nodes = new LinkedList&lt;Node&gt;();

public static void topologicalSort(Graph graph) alphabetic character = new LinkedList&lt;Node&gt;();
int vertexProcessesCtr = 0;
for(Node m : graph.nodes)
}
while(!q.isEmpty()) kid : m.AdjacenctNode)
}

}
if(vertexProcessesCtr &gt; graph.vertices)


}

public static void main(String[] args) 10 = new Node("10");
Node ELEVEN = new Node("11");
Node 2 = new Node("2");
Node 3 = new Node("3");
Node 5 = new Node("5");
Node SEVEN = new Node("7");
Node EIGHT = new Node("8");
Node 9 = new Node("9");

SEVEN.AdjacenctNode.add(ELEVEN);
ELEVEN.inDegree++;
SEVEN.AdjacenctNode.add(EIGHT);
EIGHT.inDegree++;
FIVE.AdjacenctNode.add(ELEVEN);
ELEVEN.inDegree++;
THREE.AdjacenctNode.add(EIGHT);
EIGHT.inDegree++;
THREE.AdjacenctNode.add(TEN);
TEN.inDegree++;
ELEVEN.AdjacenctNode.add(TEN);
TEN.inDegree++;
ELEVEN.AdjacenctNode.add(TWO);
TWO.inDegree++;
ELEVEN.AdjacenctNode.add(NINE);
NINE.inDegree++;
EIGHT.AdjacenctNode.add(NINE);
NINE.inDegree++;

g.nodes.add(TWO);
g.nodes.add(THREE);
g.nodes.add(FIVE);
g.nodes.add(SEVEN);
g.nodes.add(EIGHT);
g.nodes.add(NINE);


System.out.println("Now line the topologial sorts");

topologicalSort(g);

}
}
class Node

public Node(String data) knowledge;
}
}