First time here? Check out the FAQ!

Ask Your Question
0

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

asked 1 year ago

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.

Preview: (hide)

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 ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

Try this:

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

where V is a given subset of vertices of G.

Preview: (hide)
link

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: 1 year ago

Seen: 184 times

Last updated: Apr 05 '23