What if you could find the smallest item instantly without checking everything?
Why BST Find Minimum Element in DSA Typescript?
Imagine you have a messy stack of books with no order, and you want to find the oldest book quickly.
You start flipping through each book one by one to find the oldest date.
Checking every book manually takes a lot of time and effort.
It's easy to miss the oldest book or get tired and make mistakes.
This slow process wastes your time and energy.
A Binary Search Tree (BST) organizes books so the oldest is always on the left side.
To find the oldest book, you just keep going left until you can't go further.
This way, you find the minimum quickly without checking every book.
function findOldestBook(books: number[]): number {
let min = books[0];
for (let i = 1; i < books.length; i++) {
if (books[i] < min) min = books[i];
}
return min;
}function findMinNode(root: TreeNode | null): TreeNode | null {
let current = root;
while (current && current.left !== null) {
current = current.left;
}
return current;
}This lets you find the smallest value in a sorted structure instantly, saving time and effort.
In a phone contact list sorted by name, finding the first contact alphabetically is like finding the minimum in a BST.
Manual search is slow and error-prone.
BST keeps data ordered to find minimum quickly.
Just follow left children to find the smallest value.