Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your work should be readable as well as correct. Always Verify Time! Write code for O(n) worst-case algorithm that verifies that a tree is actually

Your work should be readable as well as correct.

Always Verify Time!

Write code for O(n) worst-case algorithm that verifies that a tree is actually an AVL tree by detecting imbalance. If imbalance is true, then call the proper rotation function provided in the lecture slides to fix the imbalance condition.

1. Must read AVLNode data from a text file

2. Create a Book Object; and an AVL node object to be inserted into the AVL tree

3. At each insert, detect imbalance and fix the AVL tree

4. Report each imbalance detection and the node where it occurred; and output the message:

Output:

Imbalance occurred at inserting ISBN 12345; fixed in LeftRight Rotation

Imbalance occurred at inserting ISBN 87654; fixed in Left Rotation

Imbalance occurred at inserting ISBN 974321; fixed in RightLeft Rotation

class AVLNode

int key; (ISBN number)

Book value; //create a class representing a book with minimum attributes

int height;

AVLNode leftPtr;

AVLNode rightPtr;

}

You must verify the AVL balance condition at each insert and detect and fix imbalance, output result of each insertion. A null node is considered AVL property of height -1.

Java or C++ are the options.

Bonus (20%): Create a random binary tree and verify BST property and AVL balance condition. Do not hard code the tree inside the code.

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 Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

=+What kinds of problems need to be overcome?

Answered: 1 week ago

Question

=+Describe an important trade-off you recently faced

Answered: 1 week ago