Skip to main content

AVL tree for 52, 65, 72, 15, 11, 32, 20

Short answer

Final AVL tree: root 52, left child 15 (left 11, right 32 with left 20), right child 65 (right 72).

Construct an AVL Tree for given integers: 52, 65, 72, 15, 11, 32, and 20.

Insert each key as in a BST and rebalance with rotations when a node's balance factor becomes ±2.

Balance factor of a node = height(left subtree) − height(right subtree). It must stay −1, 0 or +1. After each insertion, find the nearest unbalanced ancestor of the new node and fix it:

CaseWhere the new node wentFix
LLleft subtree of left childsingle right rotation
RRright subtree of right childsingle left rotation
LRright subtree of left childleft rotation on the child, then right rotation
RLleft subtree of right childright rotation on the child, then left rotation

Step-by-step insertion

StepInsertTree after step (root(left,right))Imbalance / rotation
15252balanced
26552(-,65)balanced
37265(52,72)at 52: RR: left rotate at 52
41565(52(15,-),72)balanced
51165(15(11,52),72)at 52: LL: right rotate at 52
63252(15(11,32),65(-,72))at 65: LR: left at 15, right at 65
72052(15(11,32(20,-)),65(-,72))balanced

Final AVL tree

52
├─L:15
│  ├─L:11
│  └─R:32
│     └─L:20
└─R:65
   └─R:72

Height = 4, and every node has balance factor −1, 0 or +1.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 6 questions →