Skip to content

IsTreeGraph ​

Whether a Graph is a tree — connected, with exactly ∣V∣−1|V| - 1 edges.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageTreeGraphQ✓
IsTreeGraph(g)true iff gg is connected (underlying, direction ignored) and has exactly ∣V(g)∣−1|V(g)| - 1 edges — the standard connected-plus-edge-count tree test.
Typed signatures
TypePackageApplies
(value) -> booleancombinatoricsalways

Domain: Collections

Details
  • Wolfram calls this TreeGraphQ; this library uses the Is… spelling everywhere.

Examples

3 more kept as data, checked against the oracles
Basic #
live ↗
InIsTreeGraph(StarGraph(5))\mathrm{IsTreeGraph}(\mathrm{StarGraph}(5))OutTrue\mathrm{True}

One too many edges to be a tree

live ↗
InIsTreeGraph(CycleGraph(4))\mathrm{IsTreeGraph}(\mathrm{CycleGraph}(4))OutFalse\mathrm{False}

Right edge count, but two components

live ↗
InIsTreeGraph(Graph([1,2,3,4],[UndirectedEdge(1,2),UndirectedEdge(3,4)]))\mathrm{IsTreeGraph}(\mathrm{Graph}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack, \bigl\lbrack\mathrm{UndirectedEdge}(1, 2), \mathrm{UndirectedEdge}(3, 4)\bigr\rbrack))OutFalse\mathrm{False}
About
Examples6
Checked againstWolfram Language 5 agree
CrosswalkWolfram Language

See also: IsConnectedGraph, CompleteKaryTree