This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


gives a list of vertices of g in topologically sorted order for a directed acyclic graph g.
  • A list of vertices is topologically sorted if u precedes v for each edge .
Find the topological order of vertices:
Find the topological order of vertices:
Click for copyable input
TopologicalSort works with directed graphs:
Weighted graphs:
TopologicalSort only works with acyclic graphs:
Works with large graphs:
Sort strongly connected components instead of vertices when there are cycles:
Construct the condensation of g by finding the edges between the components:
Use the topological ordering of the strongly connected components to order the vertices of g:
The new adjacency matrix is block upper triangular:
New in 8