Minimum element in BST

Given a Binary Search Tree. The task is to find the minimum element in this given BST.

Example 1:

Input:
           5
         /    \
        4      6
       /        \
      3          7
     /
    1
Output: 1

Example 2:

Input:
             9
              \
               10
                \
                 11
Output: 9


min element will be found at the leftmost part of the tree

c++ implementation:

int minValue(Node* root)
{
    Node* temp=root;
    
    while(temp->left!=NULL)
    temp=temp->left;
    
    return temp->data;
}


Time Complexity: O(n) 
space Complexity: O(n) 
where n is the height of bst





No comments

darkmode