How to find all the vertices in the graph with the maximum degree?

Given the schedule, let's say

g = Graph[{x -> a, y -> c, a -> b, b -> c, a -> c, d -> c, a -> d, b -> d}, VertexLabels -> "Name"] 

g

How to find all the vertices in the graph with the maximum degree, i.e. list all the vertices with the largest number of edges and highlight them on the graph?

In this case, these would be the vertices {a,c} .

+6
source share
3 answers

Here's an approach using DegreeCentrality :

 (* In[41]:= *) max = Pick[VertexList[g], DegreeCentrality[g], Max[DegreeCentrality[g]]] (* Out[41]= *) {a, c} (* In[42]:= *) HighlightGraph[g, max] 

enter image description here

+5
source

You can usually select vertices by degree:

  HighlightGraph[g, Table[Style[VertexList[g][[i]], ColorData["TemperatureMap"][ VertexDegree[g][[i]]/Max[VertexDegree[g]]]], {i, VertexCount[g]}]] 

enter image description here

+5
source

Here is what I tried

 HighlightGraph[g, Part[ VertexList@g , Flatten@Position [ VertexDegree@g , Max[ VertexDegree@g ]]]] 

hg

Same thing with Pick

 HighlightGraph[g, Pick[ VertexList@g , VertexDegree@g , Max[ VertexDegree@g ]]] 
+3
source

Source: https://habr.com/ru/post/906064/


All Articles