Insert 50, 25, 75, 10, 30, 60, 80, 5, 27, 55 one at a time. After each, walk back up checking balance, and rotate the first node whose sides differ in height by two.
Building an AVL tree by inserting 10 values with rebalancing.
Insert 50. First as an ordinary BST insert: descend and attach a leaf.
Inserting 50.
50 is the first value, so it is the root.
50 is added as a leaf.
Insert 25. First as an ordinary BST insert: descend and attach a leaf.
Inserting 25.
25 attaches as the left child of 50.
25 is added as a leaf.
At 50: left height 1, right height 0, balance 1. Within one, so it stays.
Node 50 has balance 1. It is fine.
Insert 75. First as an ordinary BST insert: descend and attach a leaf.
Inserting 75.
75 attaches as the right child of 50.
75 is added as a leaf.
At 50: left height 1, right height 1, balance 0. Within one, so it stays.
Node 50 has balance 0. It is fine.
Insert 10. First as an ordinary BST insert: descend and attach a leaf.
Inserting 10.
10 attaches as the left child of 25.
10 is added as a leaf.
At 25: left height 1, right height 0, balance 1. Within one, so it stays.
Node 25 has balance 1. It is fine.
At 50: left height 2, right height 1, balance 1. Within one, so it stays.
Node 50 has balance 1. It is fine.
Insert 30. First as an ordinary BST insert: descend and attach a leaf.
Inserting 30.
30 attaches as the right child of 25.
30 is added as a leaf.
At 25: left height 1, right height 1, balance 0. Within one, so it stays.
Node 25 has balance 0. It is fine.
At 50: left height 2, right height 1, balance 1. Within one, so it stays.
Node 50 has balance 1. It is fine.
Insert 60. First as an ordinary BST insert: descend and attach a leaf.
Inserting 60.
60 attaches as the left child of 75.
60 is added as a leaf.
At 75: left height 1, right height 0, balance 1. Within one, so it stays.
Node 75 has balance 1. It is fine.
At 50: left height 2, right height 2, balance 0. Within one, so it stays.
Node 50 has balance 0. It is fine.
Insert 80. First as an ordinary BST insert: descend and attach a leaf.
Inserting 80.
80 attaches as the right child of 75.
80 is added as a leaf.
At 75: left height 1, right height 1, balance 0. Within one, so it stays.
Node 75 has balance 0. It is fine.
At 50: left height 2, right height 2, balance 0. Within one, so it stays.
Node 50 has balance 0. It is fine.
Insert 5. First as an ordinary BST insert: descend and attach a leaf.
Inserting 5.
5 attaches as the left child of 10.
5 is added as a leaf.
At 10: left height 1, right height 0, balance 1. Within one, so it stays.
Node 10 has balance 1. It is fine.
At 25: left height 2, right height 1, balance 1. Within one, so it stays.
Node 25 has balance 1. It is fine.
At 50: left height 3, right height 2, balance 1. Within one, so it stays.
Node 50 has balance 1. It is fine.
Insert 27. First as an ordinary BST insert: descend and attach a leaf.
Inserting 27.
27 attaches as the left child of 30.
27 is added as a leaf.
At 30: left height 1, right height 0, balance 1. Within one, so it stays.
Node 30 has balance 1. It is fine.
At 25: left height 2, right height 2, balance 0. Within one, so it stays.
Node 25 has balance 0. It is fine.
At 50: left height 3, right height 2, balance 1. Within one, so it stays.
Node 50 has balance 1. It is fine.
Insert 55. First as an ordinary BST insert: descend and attach a leaf.
Inserting 55.
55 attaches as the left child of 60.
55 is added as a leaf.
At 60: left height 1, right height 0, balance 1. Within one, so it stays.
Node 60 has balance 1. It is fine.
At 75: left height 2, right height 1, balance 1. Within one, so it stays.
Node 75 has balance 1. It is fine.
At 50: left height 3, right height 3, balance 0. Within one, so it stays.
Node 50 has balance 0. It is fine.
All 10 values in, 0 rotations. Height 4: an unbalanced BST with these values could be up to 10 tall.
The AVL tree is complete with height 4 after 0 rotations.