Challenge: Find the Minimum Value in a Binary Search Tree

Given the root to a Binary Search Tree, write a function to find the minimum value in that tree. A solution is placed in the "solution" section for your help, but we would suggest you solve it on your own first.

Problem Statement

Implement the findMin(rootNode) function which will find the minimum value in a given Binary Search Tree. Remember, a Binary Search Tree is a Binary Tree that satisfies the following property. An illustration is also provided to jog your memory.

NodeValues(LeftSubtree)<=CurrentNodeValue<NodeValues(RightSubTree)NodeValues(LeftSubtree)<=CurrentNodeValue<NodeValues(RightSubTree)

Input

The root node for a binary search tree

Output

Returns minimum integer value from a given binary search tree

Sample Input

The root node of an object of the BinarySearchTree class which contains data such as

bst = {
    6 -> 4,9
    4 -> 2,5
    9 -> 8,12
    12 -> 10,14
}
where parent -> leftChild,rightChild

Sample Output

2

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.