Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

em subRoot) These are the methods that you need to change: Method Discerption private TreeNode This method searches the tree and tries to search(int key,

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

em subRoot) These are the methods that you need to change: Method Discerption private TreeNode This method searches the tree and tries to search(int key, TreeNode find the node with the given key. If the key is not found it should return null, otherwise it should return the node that has the key. private boolean insert(int This method does the insertion work but key, TreeNode subRoot, should make sure that the tree is a valid Car TreeNode prev) AVL tree after the insertion. Hence, this method may call the balanceTree method. The Boolean value returned by this method is used to indicate whether the height of the subtree rooted at subRoot has changed or not. private boolean delete(int This method does the deletion work and key, TreeNode subRoot, also make sure the tree is a valid AVL tree TreeNode prev, TreeNode after the deletion. Hence, this method may data) call the balanceTree method. The deleted node should be placed in the data pace fac tl th t Department of Computer Engineering parameter passed. If the key is not found, this data parameter should not change. The Boolean value returned by this method is used to indicate whether the height of the subtree rooted at subRoot has changed or not. private void This method is used to check if the balanceTree(TreeNode subRoot node is left imbalanced var subRoot, TreeNode prev) (balFactor == 2) or right imbalanced (balFactor == -2). Then, it should call the appropriate rotation methods to re- balance the tree. private void This method replaces subRoot with its rotateLeft(TreeNode right child and makes the subRoot the left subRoot, TreeNode prev) child of the child that replaced it. private void This method replaces subRoot with its left rotate Right(TreeNode child and makes the subRoot the right subRoot, TreeNode prev) child of the child that replaced it. This method calls rotate Right with rotate RightLeft(TreeNode subRoot's right child. Then, it calls subRoot, TreeNode prev) rotateLeft on the subRoot itself. private void This method calls rotateLeft with rotateLeftRight(TreeNode subRoot's left child. Then, it calls subRoot, TreeNode prev) rotate Right on the subRoot itself. private void These are the methods that you must not change: Method Description public TreeNode This method is the interface for the user. It search(int key) just calls the private search method with the key and the root. public void insert(int key) This method is the interface for the user. If the tree is empty, this method inserts the first node of the tree. Otherwise, it just calls the private insert method with the key, root, and null (the root doesn't have a prev node). public TreeNode This method is the interface for the user. delete(int key) First it initializes a TreeNode object to null. Department of Computer Enginee This object should store the node to be deleted. Then, it just calls the private delete method with the key, root, null (the root doesn't have a prev node), and the object reference. After returning from the private delete method, it should return the deleted node. public void printTree This method prints the first 4 levels of the tree. It prints it in a way that show the parent, child relationship. For each node, it shows the key and the balance factor. private void This method is called by printTree method. printLevel(Vector nodes, It is used to print the nodes at a particular int level) level. private int minValue(int x, You may need to call this method when int y) recalculating the balance factor of a node. It returns the minimum value of x and y. private int maxValue(int x, You may need to call this method when int y) recalculating the balance factor of a node. It returns the maximum value of x and y. estejava Test.java TreeNode.java * D *AVLTree.java 1 package project2; 2 3 public class TreeNode { 4 public int key; public TreeNode left; public TreeNode right; 8 public int balFactor; 9 109 /* 11 constructor 12 */ 130 public TreeNode(int key) 14 this. key = key, 15 left = right = null; 16 balFactor 0; 17 18 ] 19 . Problems Javadoc Declaration Console errors, 1 warning, 0 others Description Warnings (1 item) Resource leak: 'sc' is never closed Resource Path Test.java /project/src/project em subRoot) These are the methods that you need to change: Method Discerption private TreeNode This method searches the tree and tries to search(int key, TreeNode find the node with the given key. If the key is not found it should return null, otherwise it should return the node that has the key. private boolean insert(int This method does the insertion work but key, TreeNode subRoot, should make sure that the tree is a valid Car TreeNode prev) AVL tree after the insertion. Hence, this method may call the balanceTree method. The Boolean value returned by this method is used to indicate whether the height of the subtree rooted at subRoot has changed or not. private boolean delete(int This method does the deletion work and key, TreeNode subRoot, also make sure the tree is a valid AVL tree TreeNode prev, TreeNode after the deletion. Hence, this method may data) call the balanceTree method. The deleted node should be placed in the data pace fac tl th t Department of Computer Engineering parameter passed. If the key is not found, this data parameter should not change. The Boolean value returned by this method is used to indicate whether the height of the subtree rooted at subRoot has changed or not. private void This method is used to check if the balanceTree(TreeNode subRoot node is left imbalanced var subRoot, TreeNode prev) (balFactor == 2) or right imbalanced (balFactor == -2). Then, it should call the appropriate rotation methods to re- balance the tree. private void This method replaces subRoot with its rotateLeft(TreeNode right child and makes the subRoot the left subRoot, TreeNode prev) child of the child that replaced it. private void This method replaces subRoot with its left rotate Right(TreeNode child and makes the subRoot the right subRoot, TreeNode prev) child of the child that replaced it. This method calls rotate Right with rotate RightLeft(TreeNode subRoot's right child. Then, it calls subRoot, TreeNode prev) rotateLeft on the subRoot itself. private void This method calls rotateLeft with rotateLeftRight(TreeNode subRoot's left child. Then, it calls subRoot, TreeNode prev) rotate Right on the subRoot itself. private void These are the methods that you must not change: Method Description public TreeNode This method is the interface for the user. It search(int key) just calls the private search method with the key and the root. public void insert(int key) This method is the interface for the user. If the tree is empty, this method inserts the first node of the tree. Otherwise, it just calls the private insert method with the key, root, and null (the root doesn't have a prev node). public TreeNode This method is the interface for the user. delete(int key) First it initializes a TreeNode object to null. Department of Computer Enginee This object should store the node to be deleted. Then, it just calls the private delete method with the key, root, null (the root doesn't have a prev node), and the object reference. After returning from the private delete method, it should return the deleted node. public void printTree This method prints the first 4 levels of the tree. It prints it in a way that show the parent, child relationship. For each node, it shows the key and the balance factor. private void This method is called by printTree method. printLevel(Vector nodes, It is used to print the nodes at a particular int level) level. private int minValue(int x, You may need to call this method when int y) recalculating the balance factor of a node. It returns the minimum value of x and y. private int maxValue(int x, You may need to call this method when int y) recalculating the balance factor of a node. It returns the maximum value of x and y. estejava Test.java TreeNode.java * D *AVLTree.java 1 package project2; 2 3 public class TreeNode { 4 public int key; public TreeNode left; public TreeNode right; 8 public int balFactor; 9 109 /* 11 constructor 12 */ 130 public TreeNode(int key) 14 this. key = key, 15 left = right = null; 16 balFactor 0; 17 18 ] 19 . Problems Javadoc Declaration Console errors, 1 warning, 0 others Description Warnings (1 item) Resource leak: 'sc' is never closed Resource Path Test.java /project/src/project

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions