Question: I need java code to Implement the Topological Sort algorithm for directed graphs and run the algorithm on the directed graph that is provided in

I need java code to Implement the Topological Sort algorithm for directed graphs and run the algorithm on the directed graph that is provided in the txt file. The pseudocode is

TOPOLOGICAL-SORT(G)

1 call DFS(G) to compute finishing times v.f for each vertex v

2 as each vertex is finished, insert it onto the front of a linked list

3 return the linked list of vertices

DFS(G):

for each vertex u G.V

u.color = WHITE

u.pi = NIL

time = 0

for each vertex u G.V

if u. color ==WHITE

DFS-VISIT(G,u)

DFS-VISIT(G,u):

time = time+1

u.d = time

u.color =GRAY

for each v G.adj[u]

if v.color ==WHITE

v.pi = u

DFS-VISIT(G,v)

u.color = BLACK

time = time+1

u.f = time

TEXT.file

9

14

5 3 0.25

7 5 0.28

5 1 0.32

0 4 0.38

0 2 0.26

7 3 0.39

1. 3 0.29

2. 7 0.34

6 2 0.40

3. 6 0.52

6 0 0.58

6 4 0.93

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!