Given the following definition of a node and binary search tree, write the member functions described below. You may declare and implement more functions if you need but you need to fully code any...


Given the following definition of a node and binary search tree, write the member functions described below. You may declare and implement more functions if you need but you need to fully code any function you call.  Any function you call will calculate towards runtime of your function.  Please ensure that the run time requirement is met to get full marks



class BST{
    struct Node{
        int data_;
        Node* left_;
        Node* right_;
        Node(int dat){
            data_=dat;
            left_=right_=nullptr;
        }
    };
    Node* root_;
    ...
};


Write the following member functions of BST:



bool BST::removeSmallest(int v);


Runtime requirement O(log n) (assuming tree is balanced)




This function removes the smallest value from subtree with root value of v


This function removes the smallest value from subtree with root value of v<br>60<br>30<br>80<br>100<br>20<br>50<br>70<br>10<br>40<br>90<br>110<br>removeSmallest(60) would remove the node 10, and return true<br>removeSmallest(80) would remove the node 70, and return true<br>removeSmallest(90) would remove the node 90, and return true (no nodes are smaller than 90 in subtree with root 90)<br>removeSmallest(55) would remove nothing and return false (55 not found)<br>

Extracted text: This function removes the smallest value from subtree with root value of v 60 30 80 100 20 50 70 10 40 90 110 removeSmallest(60) would remove the node 10, and return true removeSmallest(80) would remove the node 70, and return true removeSmallest(90) would remove the node 90, and return true (no nodes are smaller than 90 in subtree with root 90) removeSmallest(55) would remove nothing and return false (55 not found)

Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here