Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 versionStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started