# How to check if (u,v) and (v,u) edges are in a given directed graph

I have a graph and i want a module to run through all the edges of this graph and check whether (u,v) edge is in this graph and (v,u) edge is in another given graph.

• What have you tried so far? Where did you get stuck? EdgeList and MemberQ are helpful for a direct approach. – Szabolcs Jul 25 '15 at 16:17
• Well i need a loop to go through every edge and to check this, and i don't know how to do that. I have this code, but it doesn't work – Nasi Jofce Jul 25 '15 at 22:31
• edgelist = {s -> 1, s -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 3 -> t, 4 -> 3, 4 -> t}; createVector[C_] := Module[{newVec {}, l = Length[C], a, b}, For[i = 0, i < Length[edgelist], i++, For[j = 0, j < l, j++, If[edgelist[i] == C[j], Append[newVec, 1]; Break, If[ MatchQ[edgelist[i], {__a -> __b}] && MatchQ[C[i], {__b -> __a}], Append[newVec, -1]; Break, Append[newVec, 0]; ]; ] ] newVec ]; – Nasi Jofce Jul 25 '15 at 22:33
• I don't understand; what's all that looping about? If you have an edge list why can't you simply check to see if your edge is in it? – Mr.Wizard Jul 25 '15 at 23:50
• can you give me a sample code how to check this? for example let's check the edge (1->2) – Nasi Jofce Jul 26 '15 at 10:05

edgelist = {s -> 1, s -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 3 -> t, 4 -> 3, 4 -> t};

• @NasiJofce Look up Table, Do, Outer, and/or Subsets. I think you need to spend some time learning the basics. – Michael E2 Jul 26 '15 at 13:50