gives a list of vertices of g in topologically sorted order for a directed acyclic graph g.


uses rules vw to specify the graph g.


  • A list of vertices is topologically sorted if u precedes v for each edge uv.


open allclose all

Basic Examples  (1)

Find the topological order of vertices:

Scope  (6)

TopologicalSort works with directed graphs:

Weighted graphs:


TopologicalSort only works with acyclic graphs:

Use rules to specify the graph:

Works with large graphs:

Applications  (1)

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:

Introduced in 2010
Updated in 2015