GraphTheory[RandomGraphs] - Maple Programming Help

Home : Support : Online Help : Mathematics : Discrete Mathematics : Graph Theory : GraphTheory Package : RandomGraphs : GraphTheory/RandomGraphs/RandomTree

GraphTheory[RandomGraphs]

 RandomTree

 Calling Sequence RandomTree(n) RandomTree(n,degree

Parameters

 n - positive integer or list of vertex labels d - positive integer options - sequence of options (see below)

Description

 • The RandomTree(n)  command creates a random tree on n vertices. This is an undirected connected graph with n-1 edges. If the first input n is a positive integer, the vertices are labeled 1,2,...,n. Alternatively you may specify the vertex labels in a list.
 • Starting with the empty undirected graph T on n vertices, edges are chosen uniformly at random and inserted into T if they do do not create a cycle.  This is repeated until T has n-1 edges.
 • The option degree
 • If the option weights=m..n is specified, where m <= n are integers, the tree is a weighted graph with edge weights chosen from [m,n] uniformly at random.  The weight matrix W in the graph has datatype=integer, and if the edge from vertex i to j is not in the graph then W[i,j] = 0.
 • If the option weights=x..y where x <= y are decimals is specified, the tree is a weighted graph with numerical edge weights chosen from [x,y] uniformly at random.  The weight matrix W in the graph has datatype=float[8], that is, double precision floats (16 decimal digits), and if the edge from vertex i to j is not in the graph then W[i,j] = 0.0.
 • If the option weights=f where f is a function (a Maple procedure) that returns a number (integer, rational, or decimal number), then f is used to generate the edge weights.  The weight matrix W in the tree has datatype=anything, and if the edge from vertex i to j is not in the graph then W[i,j] = 0.
 • The random number generator used can be seeded using the randomize function.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{with}\left(\mathrm{RandomGraphs}\right):$
 > $T≔\mathrm{RandomTree}\left(10\right)$
 ${T}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 10 vertices and 9 edge\left(s\right)}}$ (1)
 > $T≔\mathrm{RandomTree}\left(10,\mathrm{weights}=1..9\right)$
 ${T}{≔}{\mathrm{Graph 2: an undirected weighted graph with 10 vertices and 9 edge\left(s\right)}}$ (2)
 > $\mathrm{IsTree}\left(T\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{WeightMatrix}\left(T\right)$
 $\left[\begin{array}{rrrrrrrrrr}{0}& {0}& {8}& {0}& {0}& {8}& {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {7}\\ {8}& {0}& {0}& {0}& {3}& {0}& {6}& {8}& {0}& {9}\\ {0}& {0}& {0}& {0}& {0}& {0}& {0}& {1}& {0}& {0}\\ {0}& {0}& {3}& {0}& {0}& {0}& {0}& {0}& {0}& {0}\\ {8}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}\\ {0}& {0}& {6}& {0}& {0}& {0}& {0}& {0}& {0}& {0}\\ {0}& {0}& {8}& {1}& {0}& {0}& {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {0}& {7}\\ {0}& {7}& {9}& {0}& {0}& {0}& {0}& {0}& {7}& {0}\end{array}\right]$ (4)
 > $T≔\mathrm{RandomTree}\left(100\right)$
 ${T}{≔}{\mathrm{Graph 3: an undirected unweighted graph with 100 vertices and 99 edge\left(s\right)}}$ (5)
 > $\mathrm{MaximumDegree}\left(T\right)$
 ${6}$ (6)
 > $T≔\mathrm{RandomTree}\left(100,\mathrm{degree}<4\right)$
 ${T}{≔}{\mathrm{Graph 4: an undirected unweighted graph with 100 vertices and 99 edge\left(s\right)}}$ (7)
 > $\mathrm{MaximumDegree}\left(T\right)$
 ${3}$ (8)