Skip to content

IsAcyclicGraph ​

Whether a Graph contains no cycle.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageAcyclicGraphQ✓
IsAcyclicGraph(g)true iff g has no cycle, respecting edge direction where g has directed edges.
Typed signatures
TypePackageApplies
(value) -> booleancombinatoricsalways

Domain: Collections

Details
  • Wolfram calls this AcyclicGraphQ; this library uses the Is… spelling everywhere.
  • A self-loop, and two vertices joined by directed edges in BOTH directions, both count as cycles. An undirected edge alone never does -- walking straight back over the SAME edge you just arrived by isn't a cycle, so a plain undirected tree reads acyclic (matches IsTreeGraph's own edges = vertices - 1 check).

Examples

Basic #
live ↗
InIsAcyclicGraph(Graph([1,2,3,4],[UndirectedEdge(1,2),UndirectedEdge(2,3),UndirectedEdge(3,4)]))\mathrm{IsAcyclicGraph}(\mathrm{Graph}(\bigl\lbrack1, 2, 3, 4\bigr\rbrack, \bigl\lbrack\mathrm{UndirectedEdge}(1, 2), \mathrm{UndirectedEdge}(2, 3), \mathrm{UndirectedEdge}(3, 4)\bigr\rbrack))OutTrue\mathrm{True}
live ↗
InIsAcyclicGraph(CycleGraph(4))\mathrm{IsAcyclicGraph}(\mathrm{CycleGraph}(4))OutFalse\mathrm{False}
live ↗
InIsAcyclicGraph(Graph([1,2],[DirectedEdge(1,2),DirectedEdge(2,1)]))\mathrm{IsAcyclicGraph}(\mathrm{Graph}(\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack\mathrm{DirectedEdge}(1, 2), \mathrm{DirectedEdge}(2, 1)\bigr\rbrack))OutFalse\mathrm{False}
About
Examples3
Checked againstWolfram Language 3 agreeSageMath 3 agree
CrosswalkWolfram Language

Implementation

mappedsagepackages/oracle/src/mappings.ts

See also: IsTreeGraph, IsPathGraph