asked 216k views
5 votes
Create an AVL Tree using these numbers: 49 67 97 19 90 6

76 1 10 81 9 36
(Show step-by-step rotation/restructuring)

asked
User Jleggio
by
7.5k points

1 Answer

4 votes

Answer:

To create an AVL Tree using these numbers: 49 67 97 19 90 6 76 1 10 81 9 36, we can follow these steps:

Insert the root node with value 49

49

/ \

NULL NULL

Insert 67 to the right of 49, causing a left rotation

67

/ \

49 NULL

/ \

NULL NULL

Insert 97 to the right of 67, causing a left rotation

67

/ \

49 97

/ \ / \

NULL NULL NULL

Insert 19 to the left of 49, causing a right-left rotation

67

/ \

19 97

/ \ / \

NULL 49 NULL

/ \

NULL NULL

Insert 90 to the right of 97, causing a left rotation

67

/ \

19 90

/ \ \

NULL 49 97

/ \

NULL NULL

Insert 6 to the left of 19, causing a right rotation

67

/ \

19 90

/ \ \

6 49 97

/ \

NULL NULL

Insert 76 to the left of 90, causing a right-left rotation

67

/ \

19 76

/ \ \

6 49 90

/ / \

NULL 79 97

/ \

NULL NULL

Insert 1 to the left of 6, causing a right rotation

67

/ \

19 76

/ \ \

1 6 90

/ / \

49 79 97

/ \

NULL NULL

Insert 10 to the right of 6, causing a left-right rotation

67

/ \

10 76

Step-by-step explanation:

answered
User Jdavies
by
8.0k points