Find a dependency order in a graph, to do so we will have to use a timed DFS
Over all complexity for matrices -> O(|V|^3)
Over all complexity for lists -> O(|V|+|E|)
|RECURSIVE FUNCTION| params (L,v,G,s)
I- set the vertex [s] to true in the visited [v] list
II- loop through all successors [t] of the vertex [s] in the graph [G]
|- if the current vertex [t] is not visited
|- call the RECURSIVE FUNCTION again
III- add the the vertex [s] at the beginning of the order list [L]
|GLOBAL FUNCTION| (G)
I- from 0 to the number of vertices perpare a list called visited [v] and set all the values to false
II- prepare an empty list [L] (this will contain the order)
III- loop through all the vertices of the Graph [for s in vertices of G]
|- if the current vertex is not visited
|- call the RECURSIVE FUNCTION
IV- return L
def TopoRec(L,v,G,s):
v[s] = true
for t successors of s in G:
if !v[t]:
TopoRec(L,v,G,t)
add s to the beginning of L
def TopoWarpper(G):
for s vertex in G:
v[s]= false
L = []
for s vertex in G:
if !v[s]:
TopoRec(L,v,G,s)
return L def TopoRec(L,v,G,s):
# set the vertex [s] to true in the visited [v] list
v[s] = true
# loop through all successors [t] of the vertex [s] in the graph [G]
for t successors of s in G:
# if the current vertex [t] is not visited
if !v[t]:
TopoRec(L,v,G,t)
# add the the vertex [s] at the beginning of the order list [L]
add s to the beginning of L
def TopoWarpper(G):
#Initialisation
# from 0 to the number of vertices perpare a list called visited [v] and set all the values to false
for s vertex in G:
v[s]= false
# prepare an empty list [L] (this will contain the order)
L = []
# Program
# loop through all the vertices of the Graph [for s in vertices of G]
for s vertex in G:
# if the current vertex is not visited
if !v[s]:
# Call TopoRec
TopoRec(L,v,G,s)
return L A strongly connected components is the set of vertices

In this example we have the following sets.
To find a SCC we will need to run the
I- Run a timed-DFS and order the vertices by decreasing end of
treatment in a list [L]. By doing so, you obtains the topological order
II- Compute the transpose of the Graph [Gt].
III- Run a DFS on [Gt] by topological order and save the returned values into sublist in a big list
Note : every time the dfs run some values will be computed and you will be saving thos value in a sublist
when the dfs finishes you save that sub list in a big a list.
example -> [[A,D,B], [C,F], [E]]
For matrices :
For lists :
