Question: Question about Haskell Language 1. When trying to find a value in a tree we can always decide which of the two sub-trees it may
Question about Haskell Language

1. When trying to find a value in a tree we can always decide which of the two sub-trees it may occur in: occurs x (Leaf y) = x == y occurs x (Node lyr) | x == y = True | y = occurs xr The standard prelude defines Data Ordering = LT EQ | GT Together with a function Compare :: Ord a => a -> a -> Ordering that decides if one value in an ordered type is less than (LT), equal to (EQ), or greater than (GT) another value. Using this function, redefine the function occurs :: Ord a => a -> Tree a -> Bool for search trees. Why is this new definition more efficient than the original version? 1. When trying to find a value in a tree we can always decide which of the two sub-trees it may occur in: occurs x (Leaf y) = x == y occurs x (Node lyr) | x == y = True | y = occurs xr The standard prelude defines Data Ordering = LT EQ | GT Together with a function Compare :: Ord a => a -> a -> Ordering that decides if one value in an ordered type is less than (LT), equal to (EQ), or greater than (GT) another value. Using this function, redefine the function occurs :: Ord a => a -> Tree a -> Bool for search trees. Why is this new definition more efficient than the original version
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
