Question: I need a code in java that contains three classes which are a tree.java, bst.java, and avl.java tree. The bst and avl should implement the
I need a code in java that contains three classes which are a tree.java, bst.java, and avl.java tree. The bst and avl should implement the tree class.
*No directories can be used*
For the tree class i need to use this interface:
The basic interface denition is as follows:
public interface ITree {
public T getItem();
public ITree find(T item);
public ITree insert(T item);
}
For traversal I need this interface:
import java.util.*;
public interface ITraversable {
public ArrayList nlr(); // Pre-order
public ArrayList lnr(); // In-order
public ArrayList lrn(); // Post-order
public ArrayList bfs(); // Breadth-first }
For rotation the inteface is:
public interface IRotatable {
public ITree rotateLeft();
public ITree rotateRight();
}
For measurement.
public interface IMeasurable {
public int size();
public int height();
}
For the avl tree class i need to implement an AVLTree class which derives from your BinaryTree class. Your AVL Tree should maintain a balance factor during item insertion, and use it to rebalance the tree automatically whenever the balance factor is determined to be 1 or 1. You should also maintain a reference to your trees parent inside the class:
public class AVLTree
private int balance;
private AVLTree
public AVLTree(T item) {
this(item, null);
}
public AVLTree(T item, AVLTree
super(item);
this.balance = 0;
this.parent = parent; }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
