AVL tree rotations (avl)
CS 362 - Spring 2011 - Ms. Katz

Due: 11pm, Thursday, March 24th     Worth: 50 points

- to practice AVL tree rotations
- to modify just enough code to solve the problem

Problem Overview
You did the AVL tree exploration. In this assignment, you will implement three of the four AVL tree rotations. The code you start with has the single right rotation. You need to add the other three following the pattern of that one. You also need to adjust the insert code to call those other rotations. The code on page 147 of the text will help with that.

I've trimmed this down to implementing the rotations and calling them. All your changes will be in the avltree.h file. Think and plan carefully. Then copy, paste, and modify the code.

Problem Specification
The ~katz362/support/avl directory contains the code for this assignment. It currently does only the single right rotation. Insertions that would trigger other rotations just insert.

Modify the avltree.h file so that it does all four rotations in a similar manner to the single right rotation. That is, it

Follow the example of the single right rotate to do the others. Draw pictures like the one below before you start changing the code. The double rotates change more pointers.

Submit your revised avltree.h as the avl assignment.

Single Right Rotation is Implemented as an Example
The singleRight function takes in an avlptr parameter passed by reference so that it can change what it points to. That's the top of the tree in the picture.

To do the rotation, the inner child will become the top node with what was the parent becoming its right child. Inner child's old right child (C) will become the old parent's left child. Three pointers must be set. Those are shown in heavy lines. Changes are made from bottom to top so that C isn't lost. Note that for this rotation, the outer child and its children are already attached correctly.

The outer child's height doesn't change. Its depth changes, but we're not keeping track of that. The old parent's height does change, so it must be recomputed. The height of the returned tree is computed as part of the insert function.