0 votes 0 votes Which is the best data structure to implement topological sort on directed graph? Heap Stack queue Array Algorithms topological-sort made-easy-test-series graph-algorithm + – Nandkishor3939 asked Jan 5, 2019 edited Mar 4, 2019 by Rishi yadav Nandkishor3939 1.4k views answer comment Share Follow See all 7 Comments See all 7 7 Comments reply Kunal Kadian commented Jan 5, 2019 reply Follow Share Stack. Using a stack toplogical sort can be done by doing dfs. 0 votes 0 votes Nandkishor3939 commented Jan 5, 2019 reply Follow Share I have used Queue here still got the correct answer ? If I use stack i am getting wrong answer 0 votes 0 votes Nandkishor3939 commented Jan 5, 2019 reply Follow Share @Kunal Kadian please help me out on this 0 votes 0 votes Kunal Kadian commented Jan 5, 2019 reply Follow Share I think your algo will give wrong ans if you add an edge from E to B. Refer this:- https://www.geeksforgeeks.org/topological-sorting/ 0 votes 0 votes Ashish Lakhmani commented Jun 24, 2019 reply Follow Share I think the question is ambiguous because both stack and queue can be used to give correct answers efficiently. Queue : We use an array of in-degrees for all the vertices and a Queue. Stack : We use dfs and Stack (given in geeksforgeeks). 0 votes 0 votes Satbir commented Jun 24, 2019 reply Follow Share Queue will not give correct result in all the cases. 0 votes 0 votes Ashish Lakhmani commented Jun 28, 2019 reply Follow Share Please refer to this article : https://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/ 1 votes 1 votes Please log in or register to add a comment.
0 votes 0 votes topological sort application dfs dfs used stack answer is stack gorya506 answered Aug 18, 2019 gorya506 comment Share Follow See all 0 reply Please log in or register to add a comment.