Professional Documents
Culture Documents
com
home / study / engineering / computer science / computer science questions and answers / language c++: 30 , 15 , 40 , 4 , 8 , 13 , 29 , 48 , 11 , 41 for th…
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.
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
#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
Answer
Final answer
output
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
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
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
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