vided code:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

provided code: 

 

In this two-part assignment, you will be coding an AVL, which is a special type of binary search tree. It must follow the same
rules as binary search trees: each node has 0-2 children, all data in the node's left subtree is less than the parent node's
data, all data in the node's right subtree is greater than the parent node's data, and every node's data is unique.
However, an AVL differs from a BST with its self-balancing rotations, which you will implement in part one of this two-part
assignment.
IMPORTANT:
• You will be given unlimited attempts on this assignment, with no cooldown between submissions.
• Please run your code before each submission to ensure that there are no formatting errors! If there are
formatting errors in your code, your code will not be graded and a submission attempt will be logged. For
more information, please review the Vocareum overview below.
AVLNode
An AVLNode class is provided to you and will be used to represent the nodes of the tree. This file should be treated as read-
only and should not be modified in any way. This AVLNode class contains getter and setter methods to access and mutate
the structure of the nodes. Please make sure that you understand how this class works, as interaction with this class is
crucial for this assignment.
Part 1 - Rotations
In the first part of this assignment, you will be implementing the rotation functionality of an AVL. There are four methods that
work in conjunction to ensure that the AVL remains balanced at all times; each of which is outlined below. For this
assignment, you will be implementing those four methods. Be sure to read the javadocs for more information!
updateHeightAndBF
Each node contains a height and balanceFactor variable. The height variable represents the height of the
node. If you recall, a node's height is max (left node's height, right node's height) + 1 where the
height of a leaf node is O and the heights of its null children are -1. The balance factor of a node should be
equal to its left child's height minus its right child's height. Since we are storing this information in each node,
you no longer need to recursively compute it.
The first step of this assignment is to implement the updateHeightAndBF method, which will, as the name suggests, update
the height and balance factor of the passed in node. There are four main steps to completing this method:
1. Store the left child height in a variable (keep in mind the height of a null node; you'll have to account for this!)
2. Store the right child height in a variable (keep in mind the height of a null node; you'll have to account for
this!)
3. Set the height of the node to be: max (left child's height, right child's height) + 1
4. Set the balance factor of the node to be: left child's height right child's height
rotateLeft & rotate Right
The rotateLeft and rotateRight methods will perform a single rotation on the passed in subtree and return the new root of the
subtree after it is rotated. Both of these methods will utilize updateHeightAndBF. Be sure to refer to the module video on
rotations for pseudocode!
Hint: Both of these methods can
completed in just 6 lines!
balance
The balance method will chain together updateHeightAnd BF, rotateLeft, and rotateRight in order to provide the
rotation functionality of an AVL. The method template is already filled out for you; simply utilize the following
chart to fill in the conditionals. More information can be found in the module videos.
Transcribed Image Text:In this two-part assignment, you will be coding an AVL, which is a special type of binary search tree. It must follow the same rules as binary search trees: each node has 0-2 children, all data in the node's left subtree is less than the parent node's data, all data in the node's right subtree is greater than the parent node's data, and every node's data is unique. However, an AVL differs from a BST with its self-balancing rotations, which you will implement in part one of this two-part assignment. IMPORTANT: • You will be given unlimited attempts on this assignment, with no cooldown between submissions. • Please run your code before each submission to ensure that there are no formatting errors! If there are formatting errors in your code, your code will not be graded and a submission attempt will be logged. For more information, please review the Vocareum overview below. AVLNode An AVLNode class is provided to you and will be used to represent the nodes of the tree. This file should be treated as read- only and should not be modified in any way. This AVLNode class contains getter and setter methods to access and mutate the structure of the nodes. Please make sure that you understand how this class works, as interaction with this class is crucial for this assignment. Part 1 - Rotations In the first part of this assignment, you will be implementing the rotation functionality of an AVL. There are four methods that work in conjunction to ensure that the AVL remains balanced at all times; each of which is outlined below. For this assignment, you will be implementing those four methods. Be sure to read the javadocs for more information! updateHeightAndBF Each node contains a height and balanceFactor variable. The height variable represents the height of the node. If you recall, a node's height is max (left node's height, right node's height) + 1 where the height of a leaf node is O and the heights of its null children are -1. The balance factor of a node should be equal to its left child's height minus its right child's height. Since we are storing this information in each node, you no longer need to recursively compute it. The first step of this assignment is to implement the updateHeightAndBF method, which will, as the name suggests, update the height and balance factor of the passed in node. There are four main steps to completing this method: 1. Store the left child height in a variable (keep in mind the height of a null node; you'll have to account for this!) 2. Store the right child height in a variable (keep in mind the height of a null node; you'll have to account for this!) 3. Set the height of the node to be: max (left child's height, right child's height) + 1 4. Set the balance factor of the node to be: left child's height right child's height rotateLeft & rotate Right The rotateLeft and rotateRight methods will perform a single rotation on the passed in subtree and return the new root of the subtree after it is rotated. Both of these methods will utilize updateHeightAndBF. Be sure to refer to the module video on rotations for pseudocode! Hint: Both of these methods can completed in just 6 lines! balance The balance method will chain together updateHeightAnd BF, rotateLeft, and rotateRight in order to provide the rotation functionality of an AVL. The method template is already filled out for you; simply utilize the following chart to fill in the conditionals. More information can be found in the module videos.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Binary numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education