Determine if a binary search tree is height balanced

Assignment Help Computer Engineering
Reference no: EM132198953

Write a function to apply left or right rotations to a binary search tree based on the height of the left and right sub-trees of the root.

The function should first determine if a binary search tree is height balanced, and if not, rotate the tree until it is.

Your algorithm may need to apply a left or right rotation multiple times.

You will not need to apply both a left and right rotation to any tree. The function should return the root of the tree.

USE ONLY THIS FUNCTION HEADER:

TreeNode* CheckHeightAndRotate(TreeNode *root);

TreeNode struct:

struct TreeNode { int key; TreeNode *leftChild; TreeNode *rightChild; TreeNode *parent; };

Example:

Input Tree: 15 / \ 8 18 / \ 5 12 / \ 3 6 Expected Output: 8 / \ 5 15 / \ / \ 3 6 12 18

Reference no: EM132198953

Questions Cloud

Delete that element from the array while keeping the other : Write a function called delete_array that takes an array of ints, its length by reference, and the index of an element to delete.
The management topic intercultural communications : Identify an organizational problem associated with the management topic Intercultural communications.
Calculate the compensated elasticities of labour supply : The wage rate rises to $25/hour and she decides to work 41.5 hours a week. At S25/hour, if she worked 49 hours a week at the new relative prices she would have.
What are the key ways to select groups in an experiment : What are the key ways to select groups in an experiment? Consumer decision trees.....
Determine if a binary search tree is height balanced : Write a function to apply left or right rotations to a binary search tree based on the height of the left and right sub-trees of the root.
How the decision would change in response to the regulation : Graphically depict the decision of the optimal time spent searching for a job. Suppose a new regulation requires all universities to supply full information.
Calculate the sum of the squares of the elements : Write a function in C that takes three parameters: the address of a two - dimensional array of type int, the number of rows in the array.
Can imaginary risks even be identified in practice : For this assignment you are to read the attached articles, "Trouble in Happyville" by Paul Portney, and "Letting Environmentalists' Preferences Count" by Peter.
Exercises to automate a business process : Assignment - Uniform Scene - use skills acquired through practical laboratory exercises to automate a business process - Interpret and construct representations

Reviews

Write a Review

Computer Engineering Questions & Answers

  How to create an html form

Create an HTML form and a corresponding Java servlet that receives one or more parameters from the form and displays the result in a servlet generated dynamic page. Use the Tomcat server to run the exercise.

  Calculates the cutoff frequency in a simple rc circuit

Write a simple Java application which calculates the cutoff frequency in a simple RC circuit. Your application should ask the user to enter the capacitor and resistor values of the circuit. You must use the JOptionPane class to collect the user's ..

  Describe the four steps of a typical plc processor scan

The actual scan time, or time it takes the PLC to complete a four-step scan, decreases as the number of program words increases.

  Create a rfp that will minimize procurement related risks

Create a 2- to 3-page Request for Proposal (RFP) that will minimize procurement related risks for this project. The RFP should contain the following components.

  Read sequence of positive integer numbers from the keyboard

Write a C++ program to read a sequence of positive integer numbers from the keyboard and save them in a list box called is 1stlnteger.

  Write a paper on rfid standards which apply to your industry

Write a 4 page research paper on the RFID standards which apply to your selected industry. If there are no specific standards that you think apply to your selec

  How to realize that the lists are incomplete

You are now going to create the final table list for Fernando's Skate Shop. Use the following preliminary field list and list of subjects to get started. Realize that the lists are incomplete and you might need to add more information as necessary..

  Use the library and the internet to collect information

write 400-600 words that respond to the following questions with your thoughts ideas and comments. be substantive and

  Explain how the data will help you achieve project goals

Fully explain what [type] information or data you need to collect for the project and justify that the data will help you achieve you project's objectives.

  What potential problems may you encounter

Your company currently has several databases and many database management applications to manage the data, including Access, Microsoft SQL, and Oracle.

  How do you feel about storing your personal data in cloud

Cloud computing has become very popular during the last few years. How do you feel about storing your personal data in the cloud with the use of encryption

  Cmg is also considering expansion into other markets

CMG's IT department consists of about 70 people. The department is broken up into the Technical Services group and an Application Development group. Project managers, business analysts, and application developers are within the application develop..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd