0
0
DSA C++programming~3 mins

Why BST Find Minimum Element in DSA C++?

Choose your learning style9 modes available
The Big Idea

What if you could find the smallest item instantly without searching everything?

The Scenario

Imagine you have a messy pile of books with no order. You want to find the oldest book, but you have to check every single one by hand.

The Problem

Looking through every book one by one takes a lot of time and effort. You might miss some or get tired, making mistakes easy.

The Solution

A Binary Search Tree (BST) keeps books sorted so the oldest book is always on the leftmost side. You just follow the left path to find it quickly and easily.

Before vs After
Before
int findMin(int arr[], int size) {
  int min = arr[0];
  for(int i = 1; i < size; i++) {
    if(arr[i] < min) min = arr[i];
  }
  return min;
}
After
Node* findMin(Node* root) {
  while(root->left != nullptr) {
    root = root->left;
  }
  return root;
}
What It Enables

This lets you find the smallest value instantly without checking every item, saving time and effort.

Real Life Example

In a phone contact list sorted by name, finding the first contact alphabetically is like finding the minimum in a BST.

Key Takeaways

Manual search is slow and error-prone.

BST structure keeps data sorted for quick minimum search.

Following left children leads directly to the minimum element.