Search code examples
pseudocodetopological-sort

Topological Sort pseudocode


I have the following pseudocode for Topological Sort

Repeat:
Find a vertex with no successor
Remove it from graph
Put It at beginning of list
Until graph is empty

My question is, should it be amended to "Find a vertex with no predecessor"?


Solution

  • Yes, it should. Successor doesn't make sense, unless, of course, you reversed all edges before performing the topological sort.