| Copyright | Copyright (C) 2021 Yoo Chung |
|---|---|
| License | GPL-3.0-or-later |
| Maintainer | dev@chungyc.org |
| Safe Haskell | Safe-Inferred |
| Language | GHC2021 |
Problems.P59
Description
Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P59.
Synopsis
- heightBalancedTrees :: Int -> [Tree ()]
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 4315