List of edges starting from a set of vertices in a directed graph

Let g be a directed graph. Let be A a set of vertices. How can I list all the edges which start from a vertex in A?

The function EdgeList can take a pattern as a second argument,

g = Graph[{1, 2, 3, 4, 5}, {1 \[DirectedEdge] 3, 1 \[DirectedEdge] 4,
1 \[DirectedEdge] 5, 2 \[DirectedEdge] 3, 2 \[DirectedEdge] 4,
2 \[DirectedEdge] 5, 3 \[DirectedEdge] 4, 3 \[DirectedEdge] 5}]


EdgeList[g, DirectedEdge[ 3, _]]
(* {3 \[DirectedEdge] 4, 3 \[DirectedEdge] 5} *)


Note that this doesn't include the edges 1 \[DirectedEdge] 3 or 2 \[DirectedEdge] 3, because they don't match the pattern.

And if A is a list of vertices, you just need to use DirectedEdge[ Alternatives @@ A, _] as your pattern.

• It seems to work. Thanks very much Jason. – Francesco Ciardiello May 13 '18 at 2:33

If G is the graph,

SparseArray[UnitStep[IncidenceMatrix[G]]]["AdjacencyLists"][[A]]


lists the indices of the edges for each vertex in A.