Remove 7 As in BST

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Given the following AVL Tree, performs these

consecutive operations and draw out the tree


in each step:

AVL Trees are just Binary Search Trees that


can rotate their nodes to try to maintain
balance.

Remove(7)
Insert (11)
Insert(12)

Two kinds of rotations single and double


Can decide which to do based on structure of tree

3
5

10
13

#$%

You have 3 nodes of importance, which we


will call x, y, and z (z is the parent of y which
is the parent of x)

6
9

If x is the right child of y, and y is the right child of


z, you do a single rotation (same goes for left child
of left child)
If x is the right child of y, and y is the left child of z,
you do a double rotation (same goes for left child
of right child)

X
7

10
13

Remove 7 as in BST

"

#$%

#$%

6
9

3
1

10

10

13

13
Single rotate

Final tree

&

#((%

#( %

6
10

3
1

10

3
13

11

13
11

Insert as in BST

Insert as in BST

12

'

#( %

#( %

6
10

3
1

13
11

Double rotate

10

3
1

12
11

12

13

Final tree
x
"*

"(

You might also like