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.

## See also

Other structural.properties:
`bfs()`

,
`component_distribution()`

,
`connect()`

,
`constraint()`

,
`coreness()`

,
`degree()`

,
`dfs()`

,
`distance_table()`

,
`edge_density()`

,
`feedback_arc_set()`

,
`girth()`

,
`is_dag()`

,
`is_matching()`

,
`knn()`

,
`laplacian_matrix()`

,
`reciprocity()`

,
`subcomponent()`

,
`subgraph()`

,
`transitivity()`

,
`unfold_tree()`

,
`which_multiple()`

,
`which_mutual()`

## Author

Tamas Nepusz ntamas@gmail.com and Gabor Csardi csardi.gabor@gmail.com for the R interface

## Examples

```
g <- sample_pa(100)
topo_sort(g)
#> + 100/100 vertices, from 0e2ef47:
#> [1] 13 14 19 22 23 26 27 29 33 38 39 41 42 43 45 46 47 49
#> [19] 50 52 53 55 56 57 59 60 61 62 63 65 66 67 68 69 70 71
#> [37] 72 73 74 75 76 77 78 79 80 81 82 84 85 86 87 88 89 90
#> [55] 91 92 93 94 95 96 97 98 99 100 10 16 2 28 40 9 18 20
#> [73] 34 35 25 58 24 64 36 32 83 48 31 37 21 54 44 51 3 12
#> [91] 17 15 30 8 11 7 6 5 4 1
```