How is topological sort bfs is different from normal bfs in terms of output…also why we dont use hashmap here?
How is topological sort bfs is different from normal bfs in terms of output......also why we dont use hashmap here?
bfs is just a traversal technique, it is then used for other various applications. topological sorting is one of it’s applications.
hashmap is not used because it provides no extra benefit, you need the nodes in order of their occurence, there is no way, u can store node in their way of occurence in a hasmap, unless they are ordered like 1, having only one connection and that in order like, 1’s child 2, 2’s child is 3 and so on, which is not how graphs are
so how does hashmap store if not in the order of their occurence?
Hello @garganshul151, first of all try to understand the both the algoes and their functionality,
Bfs,
we use bfs in cases where we need to do level by level traversal and so we can move to the other node after visiting a particular node.
Topological bfs,
In this case we can not traverse a node until we traversed all the nodes connected to it in a way directed towards that.
So we need to take care of the indegrees of the nodes so that we can check if there is still any node coming towards it or not. And if there is not any then we can take that node.
I hope it is clear to you. If Incase still there is any confusion pls let me know.