Traverse - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

GraphTheory

 Traverse
 traverse vertices of a graph

 Calling Sequence Traverse(G, t, opts)

Parameters

 G - graph t - (optional) one of breadthfirst or depthfirst; default is breadthfirst opts - (optional) one or more options as specified below

Options

 • connected=truefalse
 Specifies whether the traversal should be of a connected component. If true, the vertices visited in the traversal are only those reachable from the starting vertex; vertices in other components are not traversed. If false, all vertices in the graph are visited. The default is false.
 • output=one of iterator or list.
 Specifies whether this command returns a list encoding a traversal or an Iterator which will perform the traversal when repeatedly invoked. The default is list.
 • startvertex=a valid vertex in G
 Specifies the starting vertex for a traversal. If not provided, a vertex is chosen by Traverse.

Description

 • Traverse(G,t) returns a list or Iterator encoding a particular traversal of the vertices of G.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{C4}≔\mathrm{CycleGraph}\left(4\right)$
 ${\mathrm{C4}}{≔}{\mathrm{Graph 1: an undirected graph with 4 vertices and 4 edge\left(s\right)}}$ (1)
 > $\mathrm{Traverse}\left(\mathrm{C4}\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}\right]$ (2)
 > $\mathrm{it}≔\mathrm{Traverse}\left(\mathrm{C4},\mathrm{output}=\mathrm{iterator}\right)$
 ${\mathrm{it}}{≔}{\mathrm{Object<<140474922738496>>}}$ (3)
 > $G≔\mathrm{GraphTheory}:-\mathrm{Graph}\left(8,\left\{\left\{2,3\right\},\left\{2,5\right\},\left\{3,6\right\},\left\{6,7\right\}\right\}\right)$
 ${G}{≔}{\mathrm{Graph 2: an undirected graph with 8 vertices and 4 edge\left(s\right)}}$ (4)
 > $\mathrm{Traverse}\left(G,\mathrm{breadthfirst}\right)$
 $\left[{1}{,}{2}{,}{3}{,}{5}{,}{6}{,}{7}{,}{4}{,}{8}\right]$ (5)
 > $\mathrm{Traverse}\left(G,\mathrm{depthfirst}\right)$
 $\left[{1}{,}{2}{,}{3}{,}{6}{,}{7}{,}{5}{,}{4}{,}{8}\right]$ (6)
 > $\mathrm{Traverse}\left(G,\mathrm{connected}\right)$
 $\left[{1}\right]$ (7)
 > $\mathrm{Traverse}\left(G,\mathrm{connected},\mathrm{startvertex}=2\right)$
 $\left[{2}{,}{3}{,}{5}{,}{6}{,}{7}\right]$ (8)

Compatibility

 • The GraphTheory[Traverse] command was introduced in Maple 2022.
 • For more information on Maple 2022 changes, see Updates in Maple 2022.