I just wanted to note that *which* result you get out of the many possible ones depends not only on the algorithm, but also on the representation of the graph. The same graph can have several different representations on the computer (for example, different vertex and edge orders).

Here’s a short example (using igraph’s Mathematica interface) that shows different outputs for different representations (`g1`

and `g2`

) with different algorithms (`toposort`

is igraph, `TopologicalSort`

is Mathematica’s built-in implementation).

```
In[35]:= Needs["IGraphM`"];
In[36]:= toposort[g_] := VertexList[g][[IGTopologicalOrdering[g]]]
In[37]:= g1 = IGShorthand["0->k->t->b->1,0->a1->a2->1"];
g1 // toposort
Out[38]= {0, "k", "a1", "t", "a2", "b", 1}
In[39]:= g1 // TopologicalSort
Out[39]= {0, "a1", "a2", "k", "t", "b", 1}
In[40]:= g2 = IGShorthand["0->a1->a2->1,0->k->t->b->1"];
g2 // toposort
Out[41]= {0, "a1", "k", "a2", "t", "b", 1}
In[42]:= g2 // TopologicalSort
Out[42]= {0, "k", "t", "b", "a1", "a2", 1}
```

(Mathematica’s built-in must be using a different algorithm.)