# Interview Questions

Ritambhara Technologies - Coding Interview Preparations > Interview Questions > Algorithms > Node with maximum value in a Binary search tree

# Node with maximum value in a Binary search tree

- July 30, 2012
- Posted by: Kamal Rawat
- Category: Algorithms

No Comments

Earlier, we have seen how to find the minimum element in a Binary Search Tree.

Write a function which will return the maximum value in a binary search tree. For example: For the below Binary search tree, the function should return 40

Structure of the Node of the Tree is as given below:

struct Node { int data; Node* lptr; // Ptr to LEFT subtree Node* rptr; // ptr to RIGHT subtree };

**Solution:**

Function to get the maximum element in the tree will also be similar:

int getMaximum(Node* root) { while(root->rptr != NULL) root = root->rptr; return root->data; }