TopologicalSort

TopologicalSort[g]

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

TopologicalSort[{vw,}]

uses rules vw to specify the graph g.

Details

  • TopologicalSort is also known as topological ranking or topological ordering.
  • A list of vertices is topologically sorted if u precedes v for each edge uv.

Examples

open allclose all

Basic Examples  (1)

Find the topological order of vertices:

Scope  (6)

TopologicalSort works with directed graphs:

Weighted graphs:

Multigraphs:

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:

Wolfram Research (2010), TopologicalSort, Wolfram Language function, https://reference.wolfram.com/language/ref/TopologicalSort.html (updated 2015).

Text

Wolfram Research (2010), TopologicalSort, Wolfram Language function, https://reference.wolfram.com/language/ref/TopologicalSort.html (updated 2015).

CMS

Wolfram Language. 2010. "TopologicalSort." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/TopologicalSort.html.

APA

Wolfram Language. (2010). TopologicalSort. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TopologicalSort.html

BibTeX

@misc{reference.wolfram_2024_topologicalsort, author="Wolfram Research", title="{TopologicalSort}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/TopologicalSort.html}", note=[Accessed: 17-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_topologicalsort, organization={Wolfram Research}, title={TopologicalSort}, year={2015}, url={https://reference.wolfram.com/language/ref/TopologicalSort.html}, note=[Accessed: 17-November-2024 ]}