You are on page 1of 2

6/20/22, 10:34 PM Language C++: 30 , 15 , 40 , 4 , 8 , 13 , 29 , 48 ... | Chegg.

com

  Home Study tools


 My courses
 My books My folder Career Life 

Find solutions for your homework Search

home / study / engineering / computer science / computer science questions and answers / language c++: 30 , 15 , 40 , 4 , 8 , 13 , 29 , 48 , 11 , 41 for th…

Question: Language C++:


             30 , 15 , 40 , 4
, 8 , 13 , 29 , 48... Post a question
Answers from our experts for your tough
homework questions

Language C++: Enter question


30 , 15 , 40 , 4 , 8 , 13 , 29 , 48 , 11 , 41
For the
above mentioned sequence, insert values into AVL tree and perform
Left right rotation.

Continue to post
Expert Answer Was this answer helpful? 0 0
18 questions remaining

General guidance
My Textbook Solutions
The answer provided below has been developed in a clear step by step manner.

Astronomy Fundament... Fundament...


0th Edition
7th Edition 6th Edition
Show more 
View all solutions

Step-by-step FIRST STEP | ALL STEPS | ANSWER ONLY

Step 1 of 2


The AVL tree is the self-balancing binary search tree to search the left and right subtrees.

Explanation
Please refer to solution in this step.

Step 2 of 2


Explanation

program to insert a node in the AVL tree.


The two integers are used.
The program use the AVL tree to the sequence, insert values.
To perform left- right rotation.

Fig: AVL tree

program

#include<iostream>
using namespace std;
class Node
{
public:
int key;
Node *left;
Node *right;
int height;
};
int max(int x, int y);
int height(Node *Ni)
{
if (Ni == NULL)
return 0;
return Ni->height;
}
int max(int x, int y)
{
return (x > y);
}
Node* new1Node(int key)
{
Node* node = new1 Node();
node->key = key;
node->left = NULL;
node->right = NULL;
node->height = 1;
return(node);
}
Node *rightRotate(Node *y)
{
Node *x = y->left;
Node *T2 = x->right;
x->right = y;
y->left = T2;
return x;
}
Node *left Rotate(Node *x)
{
Node *y = x->right;
Node *T2 = y->left;
y->left = x;
x->right = T2;
x->height = max(height(x->left),
return y;
}
int get-Balance(Node *N)
{
if (N == NULL)
return 0;
return height(N->left) - height(N->right);
}
if (balance > 3 && key > node->left->key)
{
node->left = left Rotate(node->left);
return right Rotate(node);
}
if (balance < -2 && key < node->right->key)
{
node->right = right-Rotate(node->right);
return left-Rotate(node);
}
return node;
}
void pre-Order(Node *root)
{
if(root != NULL)
{
cout << root> << " ";
pre-Order(root0->left);
pre-Order(root1->right);
}
}
int main()
{
Node *root = NULL;
root0 = insert(root, 48);
root1 = insert(root, 41);
root2 = insert(root, 40);
root 3= insert(root, 30);
root4 = insert(root, 29);
root5 = insert(root, 15);
root6 = insert(root, 13);
root7 = insert(root, 8);
root8 = insert(root, 4);
cout << "constructed AVL tree is \n";
pre (root);
return 0;
}

output

Explanation

Please refer to solution in this step.

Answer
Final answer

output

Questions viewed by other students

Q: Urgent!!
Question:Write a C++ Code Using DSA
concepts:
30 , 15 , 40 , 4 , 8 , 13 , 29 , 48 , 11 , 41
For the above mentioned
sequence, insert values into AVL tree
and perform Left right rotation.

A: See answer

Q: Q. write C++ code for


40 , 25 , 50 , 9 , 8 , 14 , 30 , 45 , 12 , 48
For the above mentioned sequence, insert values into AVL
tree
and perform right left rotation.

A: See answer

Show more 

https://www.chegg.com/homework-help/questions-and-answers/language-c-30-15-40-4-8-13-29-48-11-41-mentioned-sequence-insert-values-avl-tree-perform-l-q92206055?trackid=e440e1cb0ff7&strackid=a612f9226739 1/2
6/20/22, 10:34 PM Language C++: 30 , 15 , 40 , 4 , 8 , 13 , 29 , 48 ... | Chegg.com

  Home Study tools


 My courses
 My books My folder Career Life 

COMPANY LEGAL & POLICIES CHEGG PRODUCTS AND SERVICES CHEGG NETWORK CUSTOMER SERVICE

About Chegg Advertising Choices Cheap Textbooks Chegg Math Solver EasyBib Customer Service
Chegg For Good Cookie Notice Chegg Coupon Mobile Apps Internships.com Give Us Feedback
College Marketing General Policies Chegg Play Sell Textbooks Thinkful Manage Subscription
Corporate Development Intellectual Property Rights Chegg Study Help Solutions Manual
Investor Relations Terms of Use College Textbooks Study 101
Jobs Global Privacy Policy eTextbooks Textbook Rental
Join Our Affiliate Program DO NOT SELL MY INFO Flashcards Used Textbooks
Media Center Honor Code Learn Digital Access Codes
Site Map Honor Shield Uversity Chegg Life
Chegg Writing

© 2003-2022 Chegg Inc. All rights reserved.

https://www.chegg.com/homework-help/questions-and-answers/language-c-30-15-40-4-8-13-29-48-11-41-mentioned-sequence-insert-values-avl-tree-perform-l-q92206055?trackid=e440e1cb0ff7&strackid=a612f9226739 2/2

You might also like