In this problem you have to write several functions for generic binary trees. The definition of the trees is given by:
That is, a tree with elements of type a is, either an empty tree, either a node with an element (of type a) and two other trees of the same type. The deriving (Show) statement simply enables an visualization of trees.
Scoring
Each function scores 10 points.
Input
let t7 = Node 7 Empty Empty let t6 = Node 6 Empty Empty let t5 = Node 5 Empty Empty let t4 = Node 4 Empty Empty let t3 = Node 3 t6 t7 let t2 = Node 2 t4 t5 let t1 = Node 1 t2 t3 let t1' = Node 1 t3 t2 size t1 height t1 equal t2 t3 isomorphic t1 t1' preOrder t1 postOrder t1 inOrder t1 breadthFirst t1 build [1,2,4,5,3] [4,2,5,1,3] overlap (+) t2 t3 overlap (+) t1 t3
Output
7 3 False True [1,2,4,5,3,6,7] [4,5,2,6,7,3,1] [4,2,5,1,6,3,7] [1,2,3,4,5,6,7] Node 1 (Node 2 (Node 4 Empty Empty) (Node 5 Empty Empty)) (Node 3 Empty Empty) Node 5 (Node 10 Empty Empty) (Node 12 Empty Empty) Node 4 (Node 8 (Node 4 Empty Empty) (Node 5 Empty Empty)) (Node 10 (Node 6 Empty Empty) (Node 7 Empty Empty))