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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!