Closed dhruviagrawal closed 3 years ago
@dhruviagrawal Add a little description about the implementation, thanks.
Is this sufficient or should I give an explanation of the entire code?
Is this sufficient or should I give an explanation of the entire code?
It's enough. thanks for your contribution. Make sure you star the repository for the confirmation.
Topological-Sort-BFS
Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge u->v, vertex u comes before v in the ordering. Topological Sorting for a graph is not possible if the graph is not a DAG.
Intuition- indegree zero nodes won't have any edges so they are placed before. Indegree is being reduced as zero indegree nodes were taken beforehand. We do this using a queue.