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.P59

Description

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

Synopsis

Documentation

heightBalancedTrees :: Int -> [Tree ()] Source #

In a height-balanced binary tree, the following property holds for every node: The height of its left subtree and the height of its right subtree are almost equal, which means their difference is not greater than one.

Construct a list of all height-balanced binary trees with the given maximum height.

Examples

>>> printTreeList $ heightBalancedTrees 2
[ Branch () (Branch () Empty Empty) Empty
, Branch () (Branch () Empty Empty) (Branch () Empty Empty)
, Branch () Empty (Branch () Empty Empty) ]
>>> length $ heightBalancedTrees 4
315