Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are given the following data type and functions in Haskell: data Tree = Lf | Nd Int Tree Tree deriving Show = insertTree ::
You are given the following data type and functions in Haskell: data Tree = Lf | Nd Int Tree Tree deriving Show = insertTree :: Int -> Tree -> Tree insertTree n L = (Nd n Lf Lf) insertTree n (Nd m left right) | m n = Nd m (insertTree n left) right | otherwise = (Nd m left right) list2tree :: [Int] => Tree list2tree ( = Lf list2tree (n:ns) insert Tree n (list2tree ns) = tree2list :: Tree -> [Int] tree2list LE 0 tree2list (Nd n left right) = tree2list left ++ [n] ++ tree2list right mergeTrees :: Tree -> Tree -> Tree merge Trees ti t2 = foldr insertTree t2 (tree2list tl) findDepth :: Int -> Tree -> Int findDepth _ Lf = -1 findDepth n (Nd m left right) | n == m = 0 | n m = if d2 == -1 then -1 else d2 + 1 where di = findDepth n left d2 = findDepth n right What will be the output of the following expressions? a. tree2list (mergeTrees (list2tree (2,1,3,4]) (list2tree (1,6,4,5))) b. findDepth i (list2tree [1,2,4,6,8,10))
Step 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