2
$\begingroup$

Given the following directed graph, is there a way to delete all edges that contain a specified vertex label name. For instance, suppose the edge list below was read in. Any edge in that list with a vertex labeled by x would be deleted, along with the vertices on both sides of that edge. For example, in the edge list below, the graph would be generated for just the edges N4 -> N5, N6 -> N2, N6 -> N3, N6 -> N4, N1 -> N8, N2 -> N8, N4 -> N8, N7 -> N8, N9 -> N7, N9 -> N8

edges = {N1 -> x, x -> N3, x -> x, N4 -> N5, N6 -> N2, N6 -> N3, 
  N6 -> N4, N1 -> N8, N2 -> N8, N4 -> N8, N7 -> N8, N9 -> N7, N9 -> N8}
g = Graph[edges, VertexLabels -> Automatic]
$\endgroup$

1 Answer 1

2
$\begingroup$

You can use VertexDelete[g,v] to delete vertex $v$ and all edges connected to $v$.

VertexDelete[g, x]

enter image description here

$\endgroup$
1
  • $\begingroup$ Oh, yes; of course!! ... Many thanks kglr!! $\endgroup$
    – user42700
    May 17, 2023 at 2:36

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.