Trees

Paul Rubin no.email at nospam.invalid
Thu Jan 22 08:16:11 CET 2015


Ian Kelly <ian.g.kelly at gmail.com> writes:
> How do you create a tree containing an even number of elements under
> this constraint?

That's a good point, I've usually seen different definitions of trees,
e.g.

   data Tree a = Leaf | Branch a (Tree a) (Tree a)

so a Leaf node doesn't have a value associated with it.

  https://en.wikipedia.org/wiki/File:Red-black_tree_example.svg

has a picture of such a tree--don't worry about the node coloring for
this purpose.  Or the multi-way tree with arbitrary branching width:

   data RoseTree a = RoseTree a [RoseTree a]

Each node has a value and a list of zero or more subtrees.



More information about the Python-list mailing list