What is a balanced binary search tree (AVL tree)?

Why Interviewers Ask This

This tests whether you can apply Data Structures & Algorithms knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

An AVL tree (Adelson-Velsky and Landis, 1962) is a self-balancing binary search tree where the heights of the left and right subtrees of every node differ by at most 1 (balance factor ∈ {-1, 0, 1}). Operations take O(log n) guaranteed because height is always O(log n). Balance factor = height(left subtree) - height(right subtree). Rebalancing with rotations: after insert/delete, if balance factor becomes ±2, perform rotations to restore balance. Four cases: (1) Left-Left (LL): single right rotation; (2) Right-Right (RR): single left rotation; (3) Left-Right (LR): left rotation on left child, then right rotation; (4) Right-Left (RL): right rotation on right child, then left rotation. Time: O(log n) for search, insert, delete — guaranteed. Space: O(n) + O(1) per node (balance factor). Comparison with Red-Black Trees: AVL trees are more strictly balanced (faster lookups), but require more rotations during insert/delete; Red-Black trees allow slightly looser balance (max height 2log n), fewer rotations — better for write-heavy workloads. Java TreeMap/TreeSet use Red-Black trees. AVL trees are used when read-heavy operations dominate.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.