Question: Need the solution in Java. Please paste the output of the running program too. The program will be utilizing Kosarajus algorithm in order to find

Need the solution in Java. Please paste the output of the running program too.

The program will be utilizing Kosarajus algorithm in order to find strongly connected components in directed graphs.

You must use adjacency list representation for storing and processing the graph.

A stack data structure can be used where you will be pushing a vertex v once call to dfs(v) is done in the first phase.

The first phase will be where you perform DFS on the reverse of the graph. Doing this will mean when the vertices are popped from the stack they will be in reverse post order.

The time complexity of implementation of Kosarrajus algorithm needs to be in order O(V+E).

The program needs to read the input from stdin

Sample input

N E

A1 b1

A2 b2

A3 b3

. . . .

Ae be

N represents the total # of vertices in the graph. Assume vertices are numbered from 0 to n-1. E represents the total # of edges of the graph. Following lines represent edges, one per line. Assume edges are directed from vertex ai to vertex bi. Do not assume the order of the edges. They may be presented in any order. It is fine to assume the input data will be consistent.

The output needs to be written to stdout. Print # of strongly connected components of the graph first. Second, print vertices in each of the connected components. Sample output The graph has 2 strongly connected components Connected component #0: 4,2,6,1 Connected component #1: 5,2,1,3

You must also show a kernel graph of the graph given.

It should be output in the same format as the output of the input graph.

Do not show parallel edges or loops.

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!