1
$\begingroup$

Given a directed graph $G(V, E)$ and set of nodes A. I'm interested to find a set of edges going from A to V-A.

  g1 = Graph[
  DirectedEdge @@@ {{1, 4}, {1, 9}, {2, 3}, {2, 4}, {2, 9}, {3, 
 2}, {3, 6}, {3, 7}, {3, 9}, {4, 1}, {4, 2}, {4, 6}, {4, 7}, {4, 
 9}, {5, 6}, {5, 9}, {6, 3}, {6, 4}, {6, 5}, {6, 9}, {7, 3}, {7, 
 4}, {7, 9}, {8, 1}, {8, 2}, {8, 3}, {8, 4}, {8, 5}, {8, 6}, {8, 
 7}}, VertexLabels -> "Name"]
 A = {8, 3, 6, 5, 7};
 (*V-A={1, 4, 9, 2}*)
$\endgroup$

1 Answer 1

2
$\begingroup$
Complement[VertexOutComponent[g1, A], A]

{1, 2, 4, 9}

EdgeList[g1, DirectedEdge[ Alternatives @@ A, 
   Alternatives @@ Complement[VertexOutComponent[g1, A], A]]]

{3 -> 2, 3 -> 9, 5 -> 9, 6 -> 4, 6 -> 9, 7 -> 4, 7 -> 9, 8 -> 1, 8 -> 2, 8 -> 4}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.