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

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