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

0

Please refer to this article :

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

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,644 questions

56,531 answers

195,623 comments

101,351 users