Stack.

Using a stack toplogical sort can be done by doing dfs.

Using a stack toplogical sort can be done by doing dfs.

The Gateway to Computer Science Excellence

+1 vote

Which is the best data structure to implement topological sort on directed graph?

- Heap
- Stack
- queue
- Array

0

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

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).

Queue : We use an array of in-degrees for all the vertices and a Queue.

Stack : We use dfs and Stack (given in geeksforgeeks).

+1

Please refer to this article :

https://www.geeksforgeeks.org/topological-sorting-indegree-based-solution/

52,345 questions

60,504 answers

201,905 comments

95,336 users