Answer:
Each time you insert a new node, call the function to adjust the sum.
This method has to be called each time we insert new node to the tree since the sum at all the
parent nodes from the newly inserted node changes when we insert the node.
// toSumTree method will convert the tree into sum tree.
int toSumTree(struct node *node)
{
if(node == NULL)
return 0;
// Store the old value
int old_val = node->data;
// Recursively call for left and right subtrees and store the sum as new value of this node
node->data = toSumTree(node->left) + toSumTree(node->right);
// Return the sum of values of nodes in left and right subtrees and
// old_value of this node
return node->data + old_val;
}
This has the complexity of O(n).
Explanation:
#Python
hasempty = False
for name in names:
if ( not name ):
hasempty = True
break # speed things up
Answer:
Option B and C are the correct answer for the above question
Explanation:
The above question asked about the work of the programmer to catch an error of the program--
- Then the option B states that the programmer needs to prints the value of the various program variable on every line of the program which is the correct solution because it is used to find the error easily. It defines the value of every variable in every place of the program and the programmer caught the error statement in the program if anywhere the variable gets the false value.
- The C option states to help from a friend, it is also a good solution because the friend can easily be caught the error of the program by seeing every line of code.
- But the other option is not correct because the option A states that the change the name of the variable which is not a result of anything.
- And the option D states that the code will be retyped again which is also not justify anything.
Answer: here is the answer ☀️keep on shining☀️
Explanation:
def min(x,y):
smallest = x
if y < smallest:
smallest = y
return smallest
x = min(2,1)
print("The min is "+str(x))
Although I wouldn't recommend using the name min for a function because min is the name of an existing function. Best of luck.