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
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd9d01fd3-079d-4577-ba3b-bc61c7663879%2F0b3f7d53-1467-4010-8b6f-24b435b0b876%2Fx6mkyww_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
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)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education