Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Topic: AVL Tree and Red / Black Tree Policy: 1 ) Each lab is due at the end of each allocated Lab Section. The TA
Topic: AVL Tree and RedBlack Tree
Policy: Each lab is due at the end of each allocated Lab Section. The TA will be available to
help you for the labhomework
Exception: if you plan to do the lab in advance, you must submit your lab answer before the
start of your allocated lab section.
Instruction:
In this exercise, you are going to learn AVL tree and RedBlack Tree. A Node class contains key,
height, left, right, color and parent is given. Class AVLTree and RedBlackTree are also given in
the same java file.
Download the provided Java file. There is a driver program class to test. Your job is to
implement the missing methods in the AVLTree class and RedBlackTree class, respectively.
Tasks: AVLTree class: Node minValueNodeNode node and Node maxValueNodeNode node
RedBlackTree class: Node rotateLeftNode node and Node rotateRightNode node
public class LabCS
public static void mainString args
AVLTree tree new AVLTree;
Constructing tree given in the above figure
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
tree.root tree.inserttreeroot, ;
he AVL Tree after deletion of
System.out.printlnInorder traversal"
of constructed tree is : ;
tree.inOrdertreeroot;
System.out.println;
System.out.printlnMaximum value in the tree is tree.maxValueNodetreerootkey;
System.out.printlnMinimum value in the tree is tree.minValueNodetreerootkey;
System.out.printlnmy Red Black Tree";
let us try to insert some data into tree and try to visualize the tree as well as traverse.
RedBlackTree t new RedBlackTree;
int arr ;
forint i;i;i
tinsertarri;
System.out.println;
tinorderTraversal;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started