Topological sort can be done using both a DFS(having edges reversed) and also using a queue . A BFS can also be done using a queue . Is there any relationship between the wa
The level by level traversal of BFS from a source node makes the nodes appear in the order of their distance from source which also means that parent nodes appear before their children nodes which are in the next level.
This might appear like what we need in a topological sort, however, stay with me. The next level in the previous sentence is the key, because if a node and its child are in the same level from source, then BFS enforces no order in traversing them meaning it may present the node's child before itself and this will be a direct violation to the rule of topological sort and the ordering is indeed important when we want a topological sort.
Although it seems like there is a relationship between BFS and topological sort, it is rather weak.