# Vertices, their labels, and how to refer to them?

In the examples I have seen, graph vertices in Mathematica are usually explicit small integers. However, Wolfram documentation says that vertices can be any arbitrary expression (eg., george, x^2, London, 5).

Nevertheless, it seems that vertices are always referred to by number, that is, by the position of the vertex expression in VertexList[gr]. This can be confusing. For example, if I build a graph like this, using nonconsecutive vertex numbers,

Graph[1<->2, 2<->10, 10<->3, 3<->4]


then I still have to refer to the vertices as if I had made each vertex number equal to its creation order, as if I had built the graph with strictly consecutive vertex numbers:

Graph[1<->2, 2<-3 ,3<->4, 4<->1]


Am I understanding this correctly?

-

No, you can refer to the vertices in any order and it will pair it accordingly. Compare the following:

g1 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, VertexLabels -> "Name"]


g2 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4},
VertexLabels -> {1 -> "a", 10 -> "b", 2 -> "c", 4 -> "d", 3 -> "e"}]


Note that in the second case, I named the vertices in a different order than what was entered and did not use sequential numbers.

-
But if I write: codeg1 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, VertexLabels -> "Name"]; GraphPlot[g1,VertexLabeling->True] then the result uses only the digits 1 through 8. That is, at the very least, confusing, don't you think? – Ralph Dratman Jul 12 '12 at 17:24