Given a graph, say
g = Graph[{x -> a, y -> c, a -> b,
b -> c, a -> c, d -> c,
a -> d, b -> d},
VertexLabels -> "Name"]
How do I find all vertices in a graph with the maximum degree i.e. a list of all vertices that has the most number of edges, and highlight them in the graph?
In this case, it would be the vertices {a,c}
.
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]
You can generally highlight vertices by their degree:
HighlightGraph[g,
Table[Style[VertexList[g][[i]],
ColorData["TemperatureMap"][
VertexDegree[g][[i]]/Max[VertexDegree[g]]]], {i, VertexCount[g]}]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With