 GraphTheory - Maple Programming Help

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

GraphTheory

 IsForest

 Calling Sequence IsForest(G)

Parameters

 G - graph

Description

 • The IsForest command returns true if the input graph is a forest or false otherwise. A forest is a graph whose connected components are all trees.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $F≔\mathrm{Graph}\left(\left[1,2,3,4,5,6\right],\left\{\left\{1,2\right\},\left\{2,3\right\},\left\{5,6\right\}\right\}\right)$
 ${F}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 6 vertices and 3 edge\left(s\right)}}$ (1)
 > $\mathrm{IsForest}\left(F\right)$
 ${\mathrm{true}}$ (2)
 > $C≔\mathrm{ConnectedComponents}\left(F\right)$
 ${C}{≔}\left[\left[{1}{,}{2}{,}{3}\right]{,}\left[{4}\right]{,}\left[{5}{,}{6}\right]\right]$ (3)
 > $\mathrm{seq}\left(\mathrm{IsTree}\left(\mathrm{InducedSubgraph}\left(F,i\right)\right),i=C\right)$
 ${\mathrm{true}}{,}{\mathrm{true}}{,}{\mathrm{true}}$ (4)
 > $\mathrm{NumberOfVertices}\left(F\right)-\mathrm{NumberOfEdges}\left(F\right)-\mathrm{nops}\left(\mathrm{ConnectedComponents}\left(F\right)\right)$
 ${0}$ (5)