Question: Complete the following Haskell function definitions. Unless stated otherwise do not use library functions that are not in the Haskell standard prelude 5. [2 marks]

Complete the following Haskell function definitions. Unless stated otherwise do not use library functions that are not in the Haskell standard prelude

Complete the following Haskell function definitions. Unless stated otherwise do not use

5. [2 marks] Consider the following definition for a binary tree data Tree a Leaf a I Node (Tree a) (Tree a) A binary tree is balanced if, at every node, the difference between the number of leaves appearing in the left and right subtree is at most one. (A tree which contains just one leaf is considered balanced.) Wite the function idreeoohtes i the tree is balanced. Hint: first write a function size: :Tree a ? Int that counts leaves in a tree isBalanced (Node (Node (Leaf 1) (Leaf 3) ) (Leaf 2)) ? True isBalanced (Node (Node (Leaf 1) (Node (Leaf 1) (Leaf 3))) (Leaf itie a e i 3)) cst False 5. [2 marks] Consider the following definition for a binary tree data Tree a Leaf a I Node (Tree a) (Tree a) A binary tree is balanced if, at every node, the difference between the number of leaves appearing in the left and right subtree is at most one. (A tree which contains just one leaf is considered balanced.) Wite the function idreeoohtes i the tree is balanced. Hint: first write a function size: :Tree a ? Int that counts leaves in a tree isBalanced (Node (Node (Leaf 1) (Leaf 3) ) (Leaf 2)) ? True isBalanced (Node (Node (Leaf 1) (Node (Leaf 1) (Leaf 3))) (Leaf itie a e i 3)) cst False

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!