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

Question about Haskell Language 1. When trying to find a value in

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

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!