I have a question about drawing tree graph. I use my iterative code to build a tree graph. Here it is.
ClearAll["Global`*"];
(*der={1,3,4,2};*)
der = Input["Add a lot of points in each level, enclosed in curly braces.
(contoh = {1,3,4,2}) : "]
awal = 1;
agab = {};
tekan = 1;
For[k = 1, k <= Count[der, _Integer] - 1, k++,
If[k == 1, mbiyen = 0, tekan = der[[k - 1]]];
For[l = 1, l <= tekan, l++,
For[j = 1, j <= der[[k]], j++,
a[j + mbiyen] =
Table[j + mbiyen \[UndirectedEdge] i, {i, awal + 1,
awal + der[[k + 1]]}];
agab = agab \[Union] a[j + mbiyen];
awal = awal + der[[k + 1]];
If[j == der[[k]], mbiyen = j + mbiyen];
];
];
];
agab
Graph[agab, VertexLabels -> "Name", ImagePadding -> 10]
Now, I use{1,3,4,2}
into input form. Then the graph looks like this
But I have a problem when the levels are more than 4. It still left the vertex. Can anyone fix this code? Or maybe change into recursive mode? Thanks in advance.
{2,3,4}
got me thinking. $\endgroup$