Similar Problems
Similar Problems not available
Topological Sorting - Leetcode Solution
LeetCode: Topological Sorting Leetcode Solution
Difficulty: Unknown
Topics: graphs
In graph theory, a topological sorting of a directed graph is a linear ordering of vertices of graph such that if there is a directed edge uv from vertex u to vertex v, u comes before v in the ordering.
Note: Graph must be directed and acyclic.
Example Input
Expected Output
0 2 1 3
Pseudocode
solution(v,Check_Visited,sortGraph):
v <- visited
for i in Graph[v]
if i is not visited
// recursive call
solution(i,Check_Visited,sortGraph)
insert v at first index of sortGraph
topologicalSort():
sortGraph =[]
for i in range(V):
if i is not visited
// call
solution(i,Check_Visited,sortGraph)
sortGraph <- print
Topological Sorting Solution Code
1