Minimum element in BST

Basic Accuracy: 62.66% Submissions: 48952 Points: 1


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

Your Task:
The task is to complete the function minValue() which takes root as the argument and returns the minimum element of BST. If the tree is empty, there is no minimum elemnt, so retutn -1 in that case.

Expected Time Complexity: O(Height of the BST)
Expected Auxiliary Space: O(Height of the BST).



def minValue(root):

    ##Your code here

    if root is None:

        return -1

    curr=root

    lis=[]

    while(curr.left!=None):

        curr=curr.left

    return curr.data


Comments

Popular posts from this blog

Large Factorial of array

Value equal to index value

Largest Element in Array