Question: Problems Work in a pair to design and implement an AVL self balanced tree of integer nodes, as detailed in section 4.4, page 123 od

Problems

Work in a pair to design and implement an AVL self balanced tree of integer nodes, as detailed in section 4.4, page 123 od the textbook. The class will have the following class definition.

class AVLNode{

AVLNode (int element);

AVLNode (int element, AVLNode leftElement, AVLNode rightElement);

int element;

AVLNode leftNode;

AVLNode rightNode; int height;

}

Notes:

The class definition is not complete. Add any methods and member variables that are needed to get your program working.

If any information is missing, go ahead and assume any valid assumption. State it in your readme file.

Write a main program to test your class. Use the following two trees to test your balancing implementation. Check at the end if the tree is balanced, by calculating its balance (check bellow definitions).

AVLNode FirstTree = new AVLNode ();

AVLNode SecondTree = new AVLNode ();

FirstTree.insertNode(27);

FirstTree.insertNode(20);

FirstTree.insertNode(25);

FirstTree.insertNode(15);

FirstTree.insertNode(8);

FirstTree.insertNode(7);

FirstTree.insertNode(4);

FirstTree.insertNode(5);

FirstTree.insertNode(2);

SecondTree.insertNode(20);

SecondTree.insertNode(19);

SecondTree.insertNode(15);

SecondTree.insertNode(16);

SecondTree.insertNode(27);

SecondTree.insertNode(29);

SecondTree.insertNode(28);

SecondTree.insertNode(4);

SecondTree.insertNode(5);

SecondTree.insertNode(2);

SecondTree.insertNode(1);

Height of a tree is defined as:

height(empty tree)=0 height(leave)=1

height(node) = 1 + max (height (node.left, node.right)

Balance is defined as:

balance(node)= height(node.right) height(node.left);

balance(tree)= balance (root node);

A tree is balanced if its balance = 0, 1, or -1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!