I've got spanning tree for some weighted graph (edges labeled 1-6) - for example:
graphMatrix = {{0, 0.140892, 0.298153, 1.13827, 1.27866, 1.4}, {0.140892, 0,
0.167897, 1.16492, 1.3422, 1.49614}, {0.298153, 0.167897, 0,
1.13035, 1.35045, 1.54743}, {1.13827, 1.16492, 1.13035, 0, 0.375184,
0.773562}, {1.27866, 1.3422, 1.35045, 0.375184, 0, 0.412249}, {1.4,
1.49614, 1.54743, 0.773562, 0.412249, 0}};
graph = Graph[WeightedAdjacencyGraph[graphMatrix],
VertexLabels -> "Name"];
tree = Graph[FindSpanningTree[graph], VertexLabels -> "Name"]
How can I get vertices of tree in order in which they appear in this tree?
(In this case it should be {1,2,3,4,5,6}
).
Edit: Second example, when given such tree:
Result should be {68, 2, 193, 88, 129, …}
or {197, 198, …}
VertexList[tree]
does the right thing... $\endgroup$VertexList
returns all vertices in the order they are appear in the input toGraph
. So, if you don't use an explicit vertex list as the first argument inGraph
VertexList
gives the vertices in the order they appear in the edge list you enter as the first argument ofGraph
. Try, for example,g= Graph[{3 -> 1, 1 -> 2}]; VertexList[g]
. $\endgroup$