0% found this document useful (0 votes)
37 views2 pages

Remove 7 As in BST

The document describes operations on an AVL tree: 1) It shows an initial AVL tree. 2) It performs the operations "Remove(7)", "Insert (11)", and "Insert(12)" on the tree, drawing the resulting tree after each step. 3) It explains that AVL trees use rotations to maintain balance, and describes single and double rotations that can occur depending on the structure of the tree.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Remove 7 As in BST

The document describes operations on an AVL tree: 1) It shows an initial AVL tree. 2) It performs the operations "Remove(7)", "Insert (11)", and "Insert(12)" on the tree, drawing the resulting tree after each step. 3) It explains that AVL trees use rotations to maintain balance, and describes single and double rotations that can occur depending on the structure of the tree.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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