Question
Finish below functions in OCaml: (* Insert element x into binary search tree t. * Time complexity need to be O(h). * Do not reinsert
Finish below functions in OCaml: (* Insert element x into binary search tree t. * Time complexity need to be O(h). * Do not reinsert (duplicate) existing elements *) let rec bst_insert (cmp : 'v cmp_fun) (t : 'v binary_tree) (x : 'v) : 'v binary_tree = (* TODO, replace t *) t
-
Give this function:
(* Return the minimum element of a binary search tree. *) let rec bst_min t : 'v option = match t with | Empty -> None | Node( Empty , x , _) -> Some x | Node( left , x ,right ) -> bst_min left
Finish below function:
(* Remove the minimum element of binary search tree t. * Time complexity need to be O(h). * Return a tuple containing the new binary tree and an option of the * removed element. *) let rec bst_remove_min (t : 'v binary_tree) : 'v binary_tree * 'v option = (* TODO, replace (t, None) *) (t, None)
-
(* Remove the element x from binary search tree t * Time complexity need to be O(h). * Return a tuple containing the new binary tree and a bool that is * true if the element was found and false if the element was not * found *) let rec bst_remove (cmp : 'v cmp_fun) (t : 'v binary_tree) (x : 'v) : 'v binary_tree * bool = (* TODO, replace (t, false) *) (t, false)
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