CIS 120 Final: CIS 120 UPenn Final 15sp solutions Exam

21 views21 pages

Document Summary

Recall a type of integer carrying binary search trees in ocaml. type tree = | node of tree * int * tree. An example of such a tree is given by: let t : tree = We draw it like this (omitting the empty values): Each code snippet below is a de nition of an insert function for binary search trees. Some or all of these de nitions are incorrect. Circle the result of calling each of these functions with the tree above: circle the result of insert t 6 with the following de nition. let rec insert (t:tree) (n:int) : tree = begin match t with. Node(left, x, insert right n) else t end (a) | node(left, x, right) -> if n < x then insert left n else if n > x then insert right n else t end (a)