Before we move , lets clear few concepts:-
Visiting a node :- This means doing something with the node like displaying, writing etc.
Traversing :- This means visiting each node in a specified order in a binary search tree or binary tree.
We can traverse in three ways using binary tree (we can perform these operations on binary search tree also)
1) In Order
2) Pre Order
3) Post Order

In-Order Traversal:-

In-Order Traversal:-
private void inOrder(Node localRoot)
{
if(localRoot != null)
{
inOrder(localRoot.leftChild);
System.out.print(localRoot.data);
inOrder(localRoot.rightChild);
}
}
Take the example of the above figure, we will perform the in-order traversal using below steps:-
(1) We pass node A
(2) We further go to node B
(3) We further go to left child of node B which returns null.
(4) We print node B
(5) We further go to right child of node B which returns null.
6) We come back and print node A
7) Repeat steps 2,3,4,5 for node C
8) In-Order traversing finishes.
We can use below example two study the two more options for the traversal options:-
private void preOrder(Node localRoot)
{
if(localRoot != null)
{
System.out.print(localRoot.data);
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}
}
Result : *A+BC
Result : *A+BC
private void postOrder(Node localRoot)
{
if(localRoot != null)
{
System.out.print(localRoot.data);
postOrder(localRoot.leftChild);
postOrder(localRoot.rightChild);
}
}
Result : ABC+*
Finding Maximum and Minimum value in a binary search tree:-
If we use the logic of find in binary search tree and keep going left till the node has no left children, then that is the minimum value in a binary search tree.
If we use the logic of find in binary search tree and keep going right till the node has no right children, then that is the maximum value in a binary search tree.
Result : ABC+*
Finding Maximum and Minimum value in a binary search tree:-
If we use the logic of find in binary search tree and keep going left till the node has no left children, then that is the minimum value in a binary search tree.
If we use the logic of find in binary search tree and keep going right till the node has no right children, then that is the maximum value in a binary search tree.