What if you could find the biggest number instantly without checking every single one?
Why BST Find Maximum Element in DSA Typescript?
Imagine you have a big stack of books sorted by height, but they are all mixed up on a table. You want to find the tallest book quickly.
If you try to check each book one by one, it will take a long time and you might lose track.
Checking every book manually is slow and tiring. You might miss some books or get confused about which is tallest.
Doing this with many numbers or data points by hand is even harder and error-prone.
A Binary Search Tree (BST) organizes data so that the biggest item is always easy to find by just following one path.
Finding the maximum means going right until you can't go further, making it fast and simple.
function findMaxManual(arr: number[]): number {
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] > max) max = arr[i];
}
return max;
}function findMaxBST(root: TreeNode | null): number | null {
if (!root) return null;
let current = root;
while (current.right) {
current = current.right;
}
return current.value;
}This lets you quickly find the largest value in a sorted structure without checking every item.
In a leaderboard for a game, finding the highest score fast is important. A BST helps find the top score quickly.
Manual search is slow and error-prone.
BST structure makes max value easy to find by going right.
Efficient for large sorted data sets.