avlrot - 80 35 46 20-1-2-1 65-1 X 3(a Node 46 must become a...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Left Rotations Right subtree is deeper than the left subtree so that the balance factor at node X becomes +2. (Node X is the node about which the rotation will occur.)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1. AVL tree unbalanced at node 46. The +2 balance factor indicates need for a left rotation. 24 10 46 65 80 0 0 +1 +2 +1 15 +1 X
Background image of page 2
2. (a) Child node 65 interchanges with parent 46. (b) Resulting tree is not a valid search tree. 24 10 65 46 80 0 0 +1 +2 +1 15 +1 X
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3. (a) Node 46 must become a left child of 65. (b) Node 80 moves up one level in right subtree of 65. (c) Balance factors are recomputed. AVL tree is balanced. 24 10 65 46 80 0 0 0 0 0 15 +1
Background image of page 4
Right Rotations Left subtree is deeper than the right subtree so that the balance factor at node X becomes -2. (Node X is the node about which the rotation will occur.)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1. Tree is unbalanced at node containing 46. Balance factor of –2 indicates need for a right rotation. 54 80 46 35 20 0 0 -1 -2 -1 65 -1 X
Background image of page 6
2. (a) Node 35 interchanges with parent node 46. (b) Resulting tree is not a valid search tree. 54
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 80 35 46 20-1-2-1 65-1 X 3. (a) Node 46 must become a right child of node 35. (b) Node 20 remains left child of 35 but moves up 1 level. (c) Balance factors are recomputed. AVL tree is balanced. 54 80 46 35 20 65-1 Double Rotations Insertion occurs in either: (1) In the right subtree of the left child of node X. or (2) In the left subtree of the right child of node X. (Node X is the node which becomes unbalanced) 1. Tree is unbalanced at node containing 8 due to insertion of node 5 into right subtree of left child of node 8. 12 16 8 6 5-2 14-1 +1 2 4-1-2 10 X 2. (a) Rotate X’s grandchild about X’s child (rotate 6 about 4). (b) Resulting tree is not AVL balanced. 12 16 8 2 5-2 14-2 4 6-1-2 10 X 3. (a) Rotate 6 about 8. (Rotate X’s new child about X.) (b) Tree becomes AVL balanced. 12 16 6-1 14 8-1 10 +1 X 2 5 4...
View Full Document

{[ snackBarMessage ]}

Page1 / 12

avlrot - 80 35 46 20-1-2-1 65-1 X 3(a Node 46 must become a...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online