2. One of the reasons binary trees are important is that there is a natural one-to-one correspon- dence between forests and binary trees, where a forest is a list of trees: A forest node f can be represented as a binary tree node with the first child of f as left sub-tree and the right sibling of f as the right sub-tree. Therefore one can define HASKELL functions: toBinTree :: Forest a -> BinTree a toForest :: BinTree a -> Forest a that are mutual inverses, so that for any forest f, and toForest (toBinTree f) == f 1 toBinTree (toForest b) == b for any binary tree b. For example, the following forest over Integer: 4 7 8 9 is uniquely represented by the following binary tree: 2 4 6 3 3 8 where the first sub-binary tree of a node is drawn below the node, the second sub-binary tree is drawn to the right of the node, and empty binary trees are not shown. Define the functions toBinTree and toForest.
2. One of the reasons binary trees are important is that there is a natural one-to-one correspon- dence between forests and binary trees, where a forest is a list of trees: A forest node f can be represented as a binary tree node with the first child of f as left sub-tree and the right sibling of f as the right sub-tree. Therefore one can define HASKELL functions: toBinTree :: Forest a -> BinTree a toForest :: BinTree a -> Forest a that are mutual inverses, so that for any forest f, and toForest (toBinTree f) == f 1 toBinTree (toForest b) == b for any binary tree b. For example, the following forest over Integer: 4 7 8 9 is uniquely represented by the following binary tree: 2 4 6 3 3 8 where the first sub-binary tree of a node is drawn below the node, the second sub-binary tree is drawn to the right of the node, and empty binary trees are not shown. Define the functions toBinTree and toForest.
Related questions
Question
question 2
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps