Ask Your Question
1

Does Sage have a function to determine vertex cuts?

asked 0 years ago

licheng gravatar image

I know about is_cut_vertex(G, u) for checking if a vertex is a cut-vertex. But is there a function in Sage to determine if a subset of vertices is a vertex cut? Although it's not too difficult to write, as shown below:

def is_vertex_cut(graph, subset):
    subgraph = graph.copy()
    subgraph.delete_vertices(subset)
    return not subgraph.is_connected()
Preview: (hide)

Comments

For each graph, do you want to use your function for a single subset or many? I ask because it might not be the most efficient for what you aim to do. For example, to compute the list of cut vertices there is a O(m) algorithm but running .is_cut_vertex(v) for each vertex v of the graph would be O(m^2).

vdelecroix gravatar imagevdelecroix ( 0 years ago )

Thank you. I am not testing whether a set of vertices are cut vertices individually, but rather whether a subset of vertices forms a vertex cut set. Indeed, my goal is to test many subsets to determine whether they are vertex cut sets.

licheng gravatar imagelicheng ( 0 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 0 years ago

vdelecroix gravatar image

Such function does not seem to exist. The most relevant page for such questions seems to be Connectivity related functions Alternatively, you could use the following

def is_vertex_cut_bis(graph, subset):
    new_graph = graph.copy()
    new_graph.merge_vertices(subset)
    return new_graph.is_cut_vertex(subset[0])
Preview: (hide)
link

Comments

2

The most efficient method is to do a depth-first search starting from a neighbor of subset, avoiding to visit vertices in subset. On the way, we record visited vertices. When it's done, it suffices to check if there is a vertex that has not be visited by the search and that is not in subset. This can be done in time O(n + m).

David Coudert gravatar imageDavid Coudert ( 0 years ago )

@David Coudert Your idea is worth implementing in Sage.

licheng gravatar imagelicheng ( 0 years ago )

@David Coundert Nice. A similar problem, I am not sure if there is an implementation for determining if a set of edges is a cut-set (removal results in disconnection of a graph).

licheng gravatar imagelicheng ( 0 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 0 years ago

Seen: 243 times

Last updated: Jul 22 '24