
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program to Find the Minimum value of Binary Search Tree
It is a program to find the minimum value of a binary search tree.
Algorithms
Begin Declare nd as a structure. Declare d to the integer datatype. Declare pointer lt to the structure nd type. Declare pointer lt to the structure nd type. Declare function new_nd() to the structure nd type. Declare d to the integer datatype. Pass them as a parameter. Declare pointer nd to the structure nd type. Initialize nd = (struct nd*) malloc(sizeof(struct nd)). nd->d = d. nd->lt = NULL. nd->rt = NULL. return(nd). End Begin Declare function add_node() to the structure nd type. Declare pointer nd to the structure nd type. Declare d to the integer datatype. Pass them as a parameter. if (nd == NULL) then return(new_nd(d)). else if (d <= nd->d) then nd->lt = add_node(nd->lt, d). else nd->rt = add_node(nd->rt, d). return nd. End Begin Declare minimum_val() function to the integer datatype. Declare pointer nd to the structure nd type. Pass it as a parameter. Declare pointer cur to the structure nd type. Initialize cur = nd. while (cur->lt != NULL) do cur = cur->lt. return(cur->d). Declare pointer root to the structure nd type. Initialize root = NULL. root = add_node(root, 54). add_node(root, 32). add_node(root, 25). add_node(root, 45). add_node(root, 65). add_node(root, 75). Print "The Minimum value of the given binary search tree is: ". Print the minimum value of binary tree. getchar(). End.
Example
#include <bits/stdc++.h> using namespace std; struct nd { int d; struct nd* lt; struct nd* rt; }; struct nd* new_nd(int d) { struct nd* nd = (struct nd*) malloc(sizeof(struct nd)); nd->d = d; nd->lt = NULL; nd->rt = NULL; return(nd); } struct nd* add_node(struct nd* nd, int d) { if (nd == NULL) return(new_nd(d)); else { if (d <= nd->d) nd->lt = add_node(nd->lt, d); else nd->rt = add_node(nd->rt, d); return nd; } } int minimum_val(struct nd* nd) { struct nd* cur = nd; while (cur->lt != NULL) { cur = cur->lt; } return(cur->d); } int main() { struct nd* root = NULL; root = add_node(root, 54); add_node(root, 32); add_node(root, 25); add_node(root, 45); add_node(root, 65); add_node(root, 75); cout << "The Minimum value of the given binary search tree is: " << minimum_val(root); getchar(); return 0; }
Output
The Minimum value of the given binary search tree is: 25
- Related Articles
- Find the node with minimum value in a Binary Search Tree in C++
- Program to find Inorder Successor of a binary search tree in C++
- C++ Program to Find the Minimum element of an Array using Binary Search approach
- C++ Program to Implement Randomized Binary Search Tree
- Binary Tree to Binary Search Tree Conversion in C++
- Closest Binary Search Tree Value II in C++
- C++ Program to Find Lowest Common Ancestor in a Binary Search Tree
- Python Program To Find the Smallest and Largest Elements in the Binary Search Tree
- C++ Program to Implement self Balancing Binary Search Tree
- Python Program to Sort using a Binary Search Tree
- C++ program to find minimum vertex cover size of a graph using binary search
- Program to find the kth smallest element in a Binary Search Tree in Python
- C++ Program to Search for an Element in a Binary Search Tree
- C++ Program to Check Whether a Given Tree is Binary Search Tree
- Difference between Binary Tree and Binary Search Tree

Advertisements