Ask Your Question
0

how to find the cardinality of neighbors of a set of vertices in a graph by using sagemath?

asked 2023-04-03 11:46:09 +0100

anonymous user

Anonymous

I am having list of dominating sets of a simple graph G. I need to find the cardinality of neighbors of each dominating sets. For that, first i want to know that how to find cardinality of neighbors of a set of vertices of of G by using sagemath.

edit retag flag offensive close merge delete

Comments

Recall the definition of a dominating set. If D is a dominating set of a graph G=(V,E), then for each vertex u\in V, either u is in D or it is a neighbor of a vertex in D. I assume that you are interested in the strict neighborhood of D, that is the set of vertices that are neighbors of a vertex in D but are not in D. Obviously, it's V-D and the cardinality of this set is obvious to deduce.

David Coudert gravatar imageDavid Coudert ( 2023-04-05 23:24:57 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-05 16:18:54 +0100

Max Alekseyev gravatar image

updated 2023-04-05 16:19:27 +0100

Try this:

len(set.union(*(set(G.neighbors(v)) for v in V)))

where V is a given subset of vertices of G.

edit flag offensive delete link more

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: 2023-04-03 07:41:35 +0100

Seen: 159 times

Last updated: Apr 05 '23