Learn R Programming

igraph (version 1.2.7)

topo_sort: Topological sorting of vertices in a graph

Description

A topological sorting of a directed acyclic graph is a linear ordering of its nodes where each node comes before all nodes to which it has edges.

Usage

topo_sort(graph, mode = c("out", "all", "in"))

Arguments

graph

The input graph, should be directed

mode

Specifies how to use the direction of the edges. For “out”, the sorting order ensures that each node comes before all nodes to which it has edges, so nodes with no incoming edges go first. For “in”, it is quite the opposite: each node comes before all nodes from which it receives edges. Nodes with no outgoing edges go first.

Value

A vertex sequence (by default, but see the return.vs.es option of igraph_options) containing vertices in topologically sorted order.

Details

Every DAG has at least one topological sort, and may have many. This function returns a possible topological sort among them. If the graph is not acyclic (it has at least one cycle), a partial topological sort is returned and a warning is issued.

Examples

Run this code
# NOT RUN {
g <- barabasi.game(100)
topo_sort(g)

# }

Run the code above in your browser using DataLab