Compare Balanced and Skewed Tree Heights
Core idea
Balanced search trees maintain a logarithmic height bound so search and updates do not degenerate to a linear walk. AVL trees keep the two child heights within one at every node. Red-black trees use different color constraints. A rotation changes parent-child links while preserving inorder ordering; full balancing also updates metadata and repairs ancestors.
def height(node): if node is None: return -1 return 1 + max(height(node[1]), height(node[2]))chain = (1, None, (2, None, (3, None, None)))balanced = (2, (1, None, None), (3, None, None))print(height(chain), height(balanced))Equal node counts need not imply equal heights.
Right rotation
root = [3, [2, [1, None, None], None], None]new_root = root[1]root[1] = new_root[2]new_root[2] = rootprint(new_root)The middle subtree (here empty) moves to the old root’s left.
Common mistake
A rotation alone is not an AVL implementation. A height difference at the root alone cannot establish balance throughout the tree.
Practice
Draw a rotation where the middle subtree is nonempty; verify inorder before and after.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Balanced tree concepts
Check your understanding of balanced tree concepts.
What is printed?
print(1+max(-1,-1))What is printed?
print(abs(3-1)<=1)What does a correct rotation preserve?
What height bound does balancing target?