Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone please show me step by step how to solve this problem? Also please no

ID: 3863547 • Letter: C

Question

Can anyone please show me step by step how to solve this problem? Also please note undet the Answer word theres the function with with one parameter only please make sure the code works with that

[10 points) Alexander Calder invented the mobile in 1931. We define a mobile tree as a binary tree with nodes of the following type: struct Node int weight; the weight of this node itself Node* left; Node right; Define the weight of a mobile tree to be the sum of the weights of all the nodes in the tree. The empty tree therefore has a weight ofzero.) We say that a mobile tree is in balance ifeither: it is empty, or if the weights ofits left and right subtrees are equal, and each of those subtrees is itself in balance. This mobile tree, for example, is in balance: Write a function namedisInBalance that takes a pointer to the root node ofa mobile tree and retums true if that mobile tree is in balance, or false otherwise. If you wish, you may write an additional function called by isInBalance. You must not use any global variables, nor any variables of types other than bool,bool &, int, int&, or Node You must not use the keywords while, for, goto, or static. Your solution must not be more than 30 lines ofcode. To not lose significant credit, your solution must be such that a call to isInBalance results in each node in the mobile tree being visited no more than once. Answer: bool isInBalance (Node root)

Explanation / Answer

code:


bool isInBalance(Node* root)
{
int sum;
return isBalance(root, &sum);
}
bool isBalance(node* root,*sum)
{
if(root==NULL)
return true;
int lsum=0;
int rsum=0;
bool flag1 =isBalance(root->left,&lsum);
bool flag2 =isBalance(root->right,&rsum);
*sum = root->data +lsum+rsum;
if(lsum==rsum && flag1 &&flag2)
return true
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote