---
title: "AVL tree for 10, 20, 30, 35, 50, ..."
subject: "Data Structure and Algorithm"
chapter: 6
key: "semester_4/data_structure_and_algorithm:avl-build-10-20-30-35"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/avl-build-10-20-30-35
site: BCT Engineering
---

# AVL tree for 10, 20, 30, 35, 50, ...

Data Structure and Algorithm · Chapter 6: Trees

- Asked in: 2072 Asoj, 6 marks
- Video: [Lec-59: How to Create AVL tree | LL, RR, LR, RL Rotation in AVL | Data Structure](https://www.youtube.com/watch?v=vEZ3-bdPdUQ) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/avl-build-10-20-30-35
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-6

## Question

Create an AVL balanced tree for the set of data 10, 20, 30, 35, 50, 70, 40, 80, 60, 65 by explaining each rotation rule used.

## Short answer

After insertions and rotations, the AVL tree is rooted at 35, with left child 20 (left 10, right 30) and right child 60 (left child 50 with left 40, right child 70 with left 65 and right 80).

## Answer

Insert each key as in a BST. Whenever a node gets balance factor ±2, apply the rotation for its case (LL, RR, LR or RL), stated in the table.

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:

| Case | Where the new node went | Fix |
|---|---|---|
| LL | left subtree of left child | single right rotation |
| RR | right subtree of right child | single left rotation |
| LR | right subtree of left child | left rotation on the child, then right rotation |
| RL | left subtree of right child | right rotation on the child, then left rotation |

#### Step-by-step insertion

| Step | Insert | Tree after step (root(left,right)) | Imbalance / rotation |
|---|---|---|---|
| 1 | 10 | `10` | balanced |
| 2 | 20 | `10(-,20)` | balanced |
| 3 | 30 | `20(10,30)` | at 10: RR: left rotate at 10 |
| 4 | 35 | `20(10,30(-,35))` | balanced |
| 5 | 50 | `20(10,35(30,50))` | at 30: RR: left rotate at 30 |
| 6 | 70 | `35(20(10,30),50(-,70))` | at 20: RR: left rotate at 20 |
| 7 | 40 | `35(20(10,30),50(40,70))` | balanced |
| 8 | 80 | `35(20(10,30),50(40,70(-,80)))` | balanced |
| 9 | 60 | `35(20(10,30),50(40,70(60,80)))` | balanced |
| 10 | 65 | `35(20(10,30),60(50(40,-),70(65,80)))` | at 50: RL: right at 70, left at 50 |

#### Final AVL tree

```text
35
├─L:20
│  ├─L:10
│  └─R:30
└─R:60
   ├─L:50
   │  └─L:40
   └─R:70
      ├─L:65
      └─R:80
```

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

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which fix matches the LR case?
   A. Right rotation on the child, then left rotation
   B. Single right rotation
   C. Single left rotation
   D. Left rotation on the child, then right rotation
   Answer: D. LR means the new node went in the right subtree of the left child. (Key point: Rotation table)

2. Inserting 50 into 20(10,30(-,35)) unbalances 30. Fix?
   A. RR; left rotation at 30 gives 35(30,50)
   B. LL; right rotation at 30
   C. RL; double rotation
   D. LR; double rotation
   Answer: A. 50 is right of the right child 35, so a single left rotation. (Key point: Insert 50)

3. Inserting 65 into 35(20(10,30),50(40,70(60,80))) unbalances 50, with 65 ending in the left subtree of the right child 70. Which fix at 50?
   A. RR: left at 50
   B. RL: right at 70, left at 50
   C. LR: left at 70, right at 50
   D. LL: right at 50
   Answer: B. 65 lies in the left subtree of the right child 70 (as the right child of 60), so RL double rotation applies. (Key point: Insert 65)

4. What is the root of the final AVL tree and its height?
   A. Root 10, height 10
   B. Root 60, height 4
   C. Root 35, height 4
   D. Root 35, height 3
   Answer: C. The final tree is 35(20(10,30),60(50(40,-),70(65,80))) with height 4. (Key point: Final tree)

## Related in Data Structure and Algorithm

- [AVL tree for 10 20 30 50 45 40 8 5 3](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30) — Data Structure and Algorithm, chapter 6
- [AVL tree for 52, 65, 72, 15, 11, 32, 20](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-52-65-72) — Data Structure and Algorithm, chapter 6
- [AVL tree for 24, 12, 8, 15, 35, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-24-12-8) — Data Structure and Algorithm, chapter 6
- [AVL tree for month names](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-months) — Data Structure and Algorithm, chapter 6, asked 2×
- [B-tree insertion algorithm; AVL of months](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abtree-insertion-avl-months) — Data Structure and Algorithm, chapter 6, asked 2×

## Related in other subjects

- [Cutting volume, 60 m, GL 540.70, formation 538.20](https://www.bctengineer.com/question.md?key=semester_3%2Fsurveying_i%3Avolume-cutting-60m-gl-540-70) — Surveying I, chapter 9, asked 7×
- [Three reservoirs ZA 65, ZB 70, ZC 40](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Athree-reservoir-pipes-ad-bd-dc) — Hydraulics, chapter 3
- [3D rotation about axis (1,2,3)-(10,20,30)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Arotate-3d-axis-1-2-3) — Computer Graphics, chapter 4
- [Elliptic: 2x2 grid 10/20/40/50](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Aelliptic-2x2-10-20-40-50) — Numerical Method, chapter 7, asked 5×
