why we are using level+1 for both root->right and left ?
can you explain helper function
why we are using level+1 for both root->right and left ?
can you explain helper function
hello @premang
because both left and right subtree will at level 1 higher than the current node.
that why adding 1 for both.
example
1 ------------ > level 0
/ \
2 3 ------------> both are at level 1 (which is 1 + level of parent i.e 1 + 0)
how helper(root->right,level+1);
helper(root->left,level+1); both works parallely ?
no they will not execute parallely ,
first we will make call over right subtree
and when control come back again to function we will make a functin call on left subtree
lets say we complete call for the right subtree then, value of level = 3 and now when we call left subtree how level counts from zero not from where it left for right subtree which is level = 3 ?
bro we are not modifying our value of level right?
consider this example
void function(int level){
cout<<level; // let say here its value is x
function(level+1);
cout<<level ; // here also value will remain same i,e it will print x only because this function is not modifying value of level
}
Q: when we complete printing right side of the subtree, then it goes to the left side, what the value of level and max_level there ?
let say value of level was x before calling right subtree.
after completion of right subtree we call on left subtree then also value of level will remain x.
and value of max_level will contain maximum level we have encounter so far.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.