# Streamlining the code In `convelist`, - `Map[List@@#&,cycle]` is succinctly written as `List@@@cycle`. - You can map on the second level (i.e. over the vertex indices instead of the UndirectedEdges): for instance, `Union@Reap[Map[Sow,cycle,{2}]][[2,1]]`. - Since each edge in a cycle is ordered consistently, you can just use Span to take the first vertex in each edge: `cycle[[;;,;;,1]]` Your `noIntersectionQ` can be replaced with `DisjointQ`. In `finddisjointcycles`, - If you forgo For loops, declaring `i`, `j` and `n` becomes unnecessary. Keeping in mind https://mathematica.stackexchange.com/questions/18519/is-there-a-break-equivalent-for-short-circuiting-in-table, you could use `Table`: Table[ If[DisjointQ@@listOfLists[[{i,j}]], Return[{i,j},Table]], {i,Length@listOfLists},{j,i-1}] While your functions are very useful for learning the internals of Mathematica, I'd say they're simple enough to not warrant definition. So I'd write something like finddisjointcycle[g_Graph]:= Table[ If[DisjointQ@@#[[{i,j}]],Return[{i,j},Table]], {i,Length@#},{j,i-1}]& @FindCycle[g,{10},All][[;;,;;,1]] If you want to find all such cycles, you can exploit `SequencePosition`: finddisjointcycles[g_Graph] := SequencePosition[ FindCycle[g,{10},All][[;;,;;,1]], {x_,___,y_}/;DisjointQ[x,y]:>{x,y},Overlaps->True] with the added benefit that you can simply include an extra `,1` parameter to limit it to one instance.