ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2021 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.P83

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P83.

Synopsis

Documentation

spanningTrees :: G -> [G] Source #

Mathematically, a tree is a graph with exactly one path between any two vertexes. A spanning tree of a graph is a tree which includes all vertexes of the graph.

Write a function to construct all spanning trees of a given graph.

You can use graph83 as an example graph to construct spanning trees from.

Examples

>>> length $ spanningTrees graph83
173
>>> toG (Paths [[1,2,4,5,6,7,8],[1,3],[5,10],[7,9]]) `elem` spanningTrees graph83
True

isTree :: G -> Bool Source #

Write a function which returns whether a graph is a tree using spanningTrees.

Examples

>>> isTree graph83
False
>>> isTree $ toG $ Paths [[1,2,3],[1,4,5]]
True

isConnected :: G -> Bool Source #

Write a function which returns whether a graph is connected using spanningTrees.

Examples

>>> isConnected graph83
True
>>> isConnected $ toG $ Lists ([1,2,3], [])
False

graph83 :: G Source #

Graph for use as an example for spanningTrees.