1
$\begingroup$

I would like to have a function that removes an edge from a graph and returns all remaining graphs after the operation. For example for a graph like

gr = Graph[{UndirectedEdge[y1, y2], UndirectedEdge[y2, y3], 
     UndirectedEdge[y2, y4], UndirectedEdge[y5, y3], 
     UndirectedEdge[y6, y3]}, VertexLabels -> Automatic]

enter image description here

It should return when splitting at the y2-y3 edge:

split[gr,UndirectedEdge[y2, y3]]

{

Graph[{UndirectedEdge[y1, y2], UndirectedEdge[y2, y4]}, VertexLabels -> Automatic]

,

Graph[{UndirectedEdge[y5, y3], UndirectedEdge[y6, y3]}, VertexLabels -> Automatic]

}

Or, it should return when splitting at the y1-y2 edge:

split[gr,UndirectedEdge[y1, y2]]

{

Graph[{y1}, {}, VertexLabels -> Automatic]

,

Graph[{ UndirectedEdge[y2, y3], UndirectedEdge[y2, y4], UndirectedEdge[y5, y3], UndirectedEdge[y6, y3]}, VertexLabels -> Automatic]

}

Is there a function in Mathematica that can do this? What is a quick way to do this?

$\endgroup$

1 Answer 1

3
$\begingroup$
gr2 = EdgeDelete[gr, UndirectedEdge[y2, y3]]

enter image description here

ConnectedComponents[gr2]

(*

{{y3, y5, y6}, {y1, y2, y4}}

*)

or ConnectedGraphComponents[gr2]

enter image description here

$\endgroup$
2
  • $\begingroup$ That seems to return a single graph of two disconnected components. Can one get a list of several diconnected graphs instead? $\endgroup$
    – Kagaratsch
    Nov 15, 2018 at 20:43
  • 1
    $\begingroup$ Ok, I think I got it: ConnectedGraphComponents[EdgeDelete[gr, UndirectedEdge[y2, y3]]]. Thank you for pointing this out! $\endgroup$
    – Kagaratsch
    Nov 15, 2018 at 20:45

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.