Question: Haskell question second pic is question. Sec Pic(below) Multiway trees For multiway trees we use the type definitioin data MTree = Node Char [MTree] deriving

Haskell question second pic is question. Haskell question second pic is question. Sec Pic(below) Multiway trees For

Sec Pic(below)multiway trees we use the type definitioin data MTree = Node Char

Multiway trees For multiway trees we use the type definitioin data MTree = Node Char [MTree] deriving (Eq, Show) (Node c [t1, t2,... , tkl) constructs an MTree node with label c and with subtrees t1, t2,..., t^. Thus, (Node c []) is a leaf. Note that there are no empty MTrees Example: t2 below represents the tree in Figure 2 t2 = Node ,u, [Node 'c' [], Node q' [i. Node 'n' 9 [Node 'm' [l. Node 'g' [, Node 'j' [11. Node 'y' [Node 'z' []]] To count the number of Node's in an MTree we can do something like the following: Figure 2: Tree t2 mcount1:: MTree - Int mcount 1 (Node - ts) = 1 + sumcounts ts sumCounts: [MTree] -> Int sumCounts [ sumcounts (tits) = mcount1 t + sumCounts ts or better vet:2 2Recall: (map f []) [] (sum 0 mcount2 (Node - ts) = 1 + sum (map mcount2 ts) or equivalently: concat: [la] -> [a] concatMap (a[b]) ->[a]->b] mcount3 (Node-ts) = 1 + sum [mcount3 t I t <. ts map> b) -> [a > [bl Multiway trees For multiway trees we use the type definitioin data MTree = Node Char [MTree] deriving (Eq, Show) (Node c [t1, t2,... , tkl) constructs an MTree node with label c and with subtrees t1, t2,..., t^. Thus, (Node c []) is a leaf. Note that there are no empty MTrees Example: t2 below represents the tree in Figure 2 t2 = Node ,u, [Node 'c' [], Node q' [i. Node 'n' 9 [Node 'm' [l. Node 'g' [, Node 'j' [11. Node 'y' [Node 'z' []]] To count the number of Node's in an MTree we can do something like the following: Figure 2: Tree t2 mcount1:: MTree - Int mcount 1 (Node - ts) = 1 + sumcounts ts sumCounts: [MTree] -> Int sumCounts [ sumcounts (tits) = mcount1 t + sumCounts ts or better vet:2 2Recall: (map f []) [] (sum 0 mcount2 (Node - ts) = 1 + sum (map mcount2 ts) or equivalently: concat: [la] -> [a] concatMap (a[b]) ->[a]->b] mcount3 (Node-ts) = 1 + sum [mcount3 t I t <. ts map> b) -> [a > [bl

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!