Searching starts at the root and compares your target to the current node. If they match, you are done. If the target is smaller, go left; if larger, go right. Repeat until you find it or fall off the tree into an empty spot, which means absent.
Each step throws away one subtree, so you follow a single root-to-leaf path. That means the cost is proportional to the tree's height, not its node count.
while (node && node.val !== target)
node = target < node.val ? node.left : node.right;
// node is the match or null
On a balanced tree the height is about log n, so search runs in O(log n). On a lopsided tree that degrades toward O(n), since the path can be as long as the node count. That gap is exactly why balancing matters.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓