Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ocaml Programming. (Please use the giving method/inputs to achieve. ls(list) tree (tree) sc(success continuation) fc (failure continuation) ) type 'a tree = Empty | Tree
Ocaml Programming. (Please use the giving method/inputs to achieve. ls(list) tree (tree) sc(success continuation) fc (failure continuation) )
type 'a tree = Empty | Tree of 'a tree * 'a * 'a tree(* Question 3: Finding subtrees *) (* TODO: Write a good set of tests for finding subtrees. *) let find_subtree_cps_tests: ((int list * int tree) * int tree option) list = [ ] (* TODO: Implement a CPS style find_subtree_cont function.*) let find_subtree_cps ls tree = let rec helper ls tree sc fc = raise NotImplemented in raise NotImplemented Question 3 : Finding Subtrees t2 (highlighted by the dashed circle) is a subtree of t1 (highlighted by the dashed rectangle). Nodes c, d and e are also subtrees of t1, containing a single node each; but node b is not a subtree on its own. t1 is also considered a subtree of itself. Additionally, an empty tree is a subtree of everything. A prefix of a subtree is the path from the root node of the tree (node a in our example) down to the parent node of the subtree. The path is defined as a list of nodes ( 'a list ). For instance, the prefix of t2 is [a], the prefix of subtree c (or d) is [a;b], and the prefix of t1 is [] . Given a prefix p and a binary tree t, your task is to find a subtree t ' with prefix p in t. When there are multiple subtrees with the same given prefix, you should return the leftmost subtree. Please initialize the success and failure continuations properly so that the return type is 'a tree option. The option type is defined as follows: type 'a option = None I Some of 'a Note that your implementation should be as general as possible (use the generic type 'a). If later on we would like to return a bool value instead, we only need to adjust the initial success and failure continuations (i.e. no changes should be made to helper)
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