# Find the node with minimum and maximum values in a Binary Search Tree

By | July 15, 2020

In this post, we will learn How to write a java program to find the node with minimum and maximum values in a Binary Search Tree?

If we want to find the node with minimum and maximum values in a binary search tree (BST) that is a very simple operation because of the way binary search tree (BST) is structured.

As we know that in Binary search tree, for each node the node’s left child must have a value less than its parent node value and the node’s right child must have a value greater than or equal to its parent node value. If we consider the root node of the binary search tree the left subtree must have nodes with values less than the root node value and the right subtree must have nodes with values greater than the root node value.

So, the Logic to find the node with the minimum value in a Binary search tree are as follows-

• We have to start from the root node go to its left child.
• Afterward, we have to keep traverse to the left children of each node until a node with no left child is reached and that node is a node with minimum value.

We have similar Logic to find the node with maximum value in a Binary search tree are as follows-

• We have to start from the root node and go to its right child.
• Afterward, we have to keep traverse to the right children of each node until a node with no right child is reached and that node is a node with maximum value.

Complete Souce code:

BinaryTree.java

ClientTest.java

The output of This Program:

Original Binary Search Tree in preOrder processing..
10 5 15 40 80 50
Max Element in Binary Seach Tree is:80
Min Element in Binary Seach Tree is:5

You May Also Like:

That’s all about Find the node with minimum and maximum values in a Binary Search Tree?
If you have any feedback or suggestion please feel free to drop in below comment box.