So AVL trees were invented to keep BSTs balanced automatically after every insertion or deletion.

Why unbalanced trees become slow

Think of a Binary Search Tree as a structure that splits your data at each level:

That’s why, when the tree is balanced, you only need about log₂(n) steps to find any node.

Example:

        8
      /   \\
     4     12
    / \\   /  \\
   2  6  10  14

If you search for 10, you only need 3 comparisons (8 → 12 → 10).

:( But if it’s unbalanced...

Imagine you insert sorted numbers:

1, 2, 3, 4, 5, 6, 7