Back to problems
COMP2521
AVL Tree: Height After Inserts
AVL Tree: Height After Inserts
Insert n distinct integers into an AVL tree in input order (rotating to stay balanced after each insert); print the final height.
Height is in edges: single node = 0, empty = -1.
A plain BST fed1 2 3 4 5degenerates to a chain (height 4); an AVL rotates and ends at height2. You must implement all four rotations (LL/RR/LR/RL).
Input: line 1 n; line 2 n integers.
Output: final AVL height.
Example: 5 / 1 2 3 4 5 -> 2.
Samples
stdin
5 1 2 3 4 5
expected
2
stdin
3 10 20 30
expected
1
c-dcc
14