Question: c++ binary tree, please explain to my doubts in details ( please make it clear which line of codes are you answering) will rate a

c++ binary tree,
please explain to my doubts in details ( please make it clear which line of codes are you answering)
will rate a good answer  c++ binary tree, please explain to my doubts in details (
please make it clear which line of codes are you answering) will
the 2nd picture is just for referencing

Program A/ #include /* Program B */ #include what does this line mean please explain why we put Null , Nullnete iny use o heng but Mullhere explain if (n = NULL) return : explain this line of code typedef struct Node_ { int data: struct Node_left; 7 struct Node_ right: 8) Node: 9 10 Node nl = {1. NULL, NULL}: 11 Node n2 = (2. NULL, NULL): 12 Node n3 = (3. &ni, &n2): 13 Node n4 = (4. NULL, NULL) : 14 Node n5 - (5. &n4. NULL}: 15 Node n6 = (6. &n3. &n5): 16 171 18 19 20 int xheight (Noden) 21 ( 22 if (n == NULL) return : 23 int height left = xheight (n->left): 24 int height_right = xheight (n->right); 25 int height = 1; 26 27 /* COMPLETE HERE 28 29 printf("Height of subtree rooted at 30 *d is %d ", n->data, height); 31 return height: 32 ) 33 34 int main(int argc, char** argv). 35 36 xheight(&n6): 37 return 0; 38) 39 40 41 42 43 / End of Program A */ typedef struct Node. { int data: int depth struct Node. parent: 8 ) Node: 9 10 Node n6 = {6.9. NULL} 11 Node n5 = {5.0, Xn6): 12 Node n4 = (4. 6. &n5 ): 13 Node n3 = (3. 9. &n6): 14 Node n2 = {2.9. &n3): 15 Node n1 = (1. 8. &n3): this line of cooles 16 17 Node nodes[] = {&ni. &n2. &n3. 18 &n4. &n5. &nb. NULL): 19 20 int xdepth (Node * n) 21 [ 22 23 n->depth = 1 + xdepth (n->parent): return n->depth; 25 ) 26 27 28 29 30 31 32 33 explain these 2 lines of codes 34 int main(int arge, char** argv) 35 36 for (Node * n = &nodes[0]; *n!=NULL; n++){ 37 printf("Depth of node Xd is %d ". 38 (*n)->data. xdepth (n)): 39 3 40 return 0: 41} 3 42 43 / End of Program B*/ height_right) { height = height_left; } else { height -- height_right: > The program visits the trec in depth-first order, resulting in the sequence of message The height of 1 is 1 The height of 2 is 1 The height of 3 is 2 The height of 4 is 1 The height of 5 is 2 The height of 6 is 3 (c) For a tree containing a bodes, what is the worst-case complexity of Program A? 12 marka! Solution. Regardless of the structure of the input tree, the complexity is always On) each made avaited exactly once (d) Program Balso defines a tree. Draw it using the same notations as in part (ak Solution. The tree is the same as the one in purt (a, but the arrows are revened as they go from children to their parent, as follows: (e) Program B computes the distance of each node from the root called the toks depth. What is the output of 12 marks] Program B7 Solution The depth of 1 is 3 The depth of 2 is 3 The depth of 3 is 2 The depth of 4 is 3 The depth of 5 is 2 The depth of 6 is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!