# AdjacencyList of DirectedEdges in Graph ignore edge direction

I have a simple tree graph with directed edges:

In: AdjacencyList[Graph[{a -> b, a -> c, b -> d, b -> e}], b]
Out: {a, d, e}


I wonder how I can select only the outgoing edge vertices elegantly.

{d, e}


In other words: I want the children of a vertex only.

The obvious solution for a tree is to always drop the first vertex. Sadly this approach fails for the root vertex, so there has to be some If-branching - which I want to avoid.

So far I tried VertexOutComponent and IncidenceList but non of them seems to give the option to filter by edge direction.

Do you see an elegant approach there, or will I have to keep using root checks?

• With g = Graph[{a -> b, a -> c, b -> d, b -> e}]; you can do Last /@ EdgeList[g, b \[DirectedEdge] _]. – Öskå Jan 12 '15 at 14:49
• What did you try with VertexOutComponent? "but non of them seems to give the option to filter by edge direction" $\leftarrow$ actually it does, that's why it has "Out" in the name. – Szabolcs Jan 12 '15 at 15:03
• @Szabolcs I find this whole implementation really confusing. Why doesn't an AdjacencyList for a directed graph include only vertices that are adjacent to the vertex, not also those it is adjacent from. Wouldn't that be more standard? (E.g., xlinux.nist.gov/dads/HTML/adjacencyListRep.html) Somewhat similarly for the VertexOutComponent: why does the result for a vertex include that vertex when there is no self loop? Is there a standard reference that justifies this vocabulary? – Alan Oct 2 '15 at 16:07

VertexOutComponent[g, b, 1]
(* {b, d, e} *)


This is precisely what you are looking for, plus the vertex b itself.

To retrieve the full adjacency list of a directed graph, you can also use IGAdjacencyList from IGraph/M.

g = Graph[{a -> b, a -> c, b -> d, b -> e}];


• Ah, thank you very much. What confused me is that the vertex itself is included - as in my understanding its not exactly an out component. What I use now is Drop[VertexOutComponent[g, b, 1], 1]. This truly returns all vertices from out directed edges of b. – Thomas Fankhauser Jan 13 '15 at 15:31