L15_AVLTree

L15_AVLTree - Rebalancing AVL Trees Right Single Rotation...

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

View Full Document Right Arrow Icon
Rebalancing AVL Trees Case 1: Right Single Rotation A new node is inserted into the left subtree of the left child. Case 2 Left Single Rotation A new node is inserted into the right subtree of the right child. Axis Axis Page 1 of 22
Background image of page 1

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

View Full DocumentRight Arrow Icon
Rebalancing AVL Trees Case 3: Left-Right Double Rotation A new node is inserted into the right subtree of the left child. Case 4: Right-Left Double Rotation A new node is inserted into the left subtree of the right child. Page 2 of 22
Background image of page 2
The AVL Tree ADT As we always did, we consider AVL trees as an ADT. We shall first show the ADT definition interface class. Page 3 of 22
Background image of page 3

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

View Full DocumentRight Arrow Icon
* public interface AVLTreeNode { public String getNodeKey(); public boolean equalTo(AVLTreeNode N); } public interface AVLTree { public AVLTreeNode root(); public AVLTree leftSubtree(); public AVLTree rightSubtree(); public boolean isEmpty(); public boolean equalTo(AVLTree t); public AVLTree insertNode(AVLTreeNode N); } Page 4 of 22
Background image of page 4
Now, let’s write methods that perform rotations. First, we write methods that perform SINGLE rotations. Page 5 of 22
Background image of page 5

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

View Full DocumentRight Arrow Icon
public interface AVLTree { public AVLTreeNode root(); public AVLTree leftSubtree(); public AVLTree rightSubtree(); public boolean isEmpty(); public boolean equalTo(AVLTree t); public AVLTree insertNode(AVLTreeNode N);
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 22

L15_AVLTree - Rebalancing AVL Trees Right Single Rotation...

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

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