What if you could find any book in a huge messy pile in just a few steps?
Why BST Over Plain Binary Tree in DSA Javascript - The Real Reason
Imagine you have a big box of unsorted books and you want to find a specific one quickly.
You start flipping through each book one by one, hoping to find the right title.
Searching this way is slow and tiring because you have no order to follow.
You waste time checking books that are not what you want.
A Binary Search Tree (BST) organizes books so that smaller titles go to the left and bigger titles go to the right.
This order helps you skip many books and find the one you want much faster.
function findBook(books, title) {
for (let i = 0; i < books.length; i++) {
if (books[i] === title) return i;
}
return -1;
}function findBookInBST(node, title) {
if (!node) return null;
if (node.value === title) return node;
if (title < node.value) return findBookInBST(node.left, title);
else return findBookInBST(node.right, title);
}BSTs let you find, add, or remove items quickly by following a clear order.
Phone contacts are often stored in a BST-like structure so you can quickly find a name without scrolling through the entire list.
Plain binary trees have no order, making search slow.
BSTs keep data sorted to speed up search and updates.
Using BSTs saves time and effort in many applications.