C# - CANNOT USE SYSTEM.COLLECTIONS
Implement an AVL tree. An AVL tree is a Binary Tree with the addition of the Height-Balance Property: The difference in height of internal nodes is no greater than 1.
You will expose the same public methods that you did for the Binary Tree. You will be required to implement additional methods described below.
Implementing the tree re-structuring methods will count as one of the assignments, and implementing the tree will count as another.
Required Methods -- Restructuring
TreeNode Restructure(TreeNode x) Performs a tri-node restructure, where x is the lowest node of the 3 involved. This should be able to handle single and double rotations
void Rotate(TreeNode x) Performs a rotation operation around node x (Moving higher & adjusting children accordingly) Single rotations are used when the 3 nodes in the restructure form a "line (x = right(y); y = right (z) OR x = left(y); y = left(z))
While this should be able to perform a double rotation if called twice, you may also opt to write a secondary method to perform a double rotation around x. Double rotations are performed when the 3 nodes form a zig-zag
9|Page
Optional Methods -- Restructuring
void Relink(TreeNode parent, TreeNode child, bool left) Utility method to make parent node the parent of the child, and child node the child of the parent. The bool left indicates if child is added as the left child(true) or right child(false)
Required Additional Methods - AVL Tree
bool IsBalanced(TreeNode x) Returns true if Node x is balanced (difference in children's heights <=1), false otherwise.