Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Return vertices that are adjacent to two vertices
ResourceFunction["CommonNeighbors"][g,u,v] returns a list of vertices adjacent to vertices u and v in the graph g. |
Find the common neighbors in a graph for a pair of vertices:
In[1]:= | ![]() |
Out[1]= | ![]() |
CommonNeighbors works with undirected graphs:
In[2]:= | ![]() |
Out[2]= | ![]() |
Directed graphs:
In[3]:= | ![]() |
Out[3]= | ![]() |
Weighted graphs:
In[4]:= | ![]() |
Out[4]= | ![]() |
Multigraphs:
In[5]:= | ![]() |
Out[5]= | ![]() |
Mixed graphs:
In[6]:= | ![]() |
Out[6]= | ![]() |
Find common neighbors in a large graphs:
In[7]:= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
Find common neighbors in a family network:
In[9]:= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
We can identify immediate family members of Nancy and Linda:
In[11]:= | ![]() |
Out[11]= | ![]() |
And highlight them:
In[12]:= | ![]() |
Out[12]= | ![]() |
If there are no common neighbors an empty list is returned:
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License