Join Nostr
2026-10-27 19:08:03 UTC

codementor on Nostr: Learn: Binary search tree (BST) In a BST, every value in a node's left subtree is ...

Learn: Binary search tree (BST)

In a BST, every value in a node's left subtree is smaller than the node, and every value in its right subtree is bigger.

To search, compare with the node and go left or right: one level per step. So the cost is O(height).

A balanced tree has height about log₂ n, so search is O(log n). A tree that is a chain has height n, so search is O(n).

That is why real libraries use self-balancing trees (like red-black or AVL trees), which fix the shape after each insert or delete.

#tg002 · TG-002-N