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

7) Which line of code should replace/*** insert code ***/ , in the function show

ID: 3545745 • Letter: 7

Question

7) Which line of code should replace/*** insert code***/,in the function shown below, if the goal of the function is to return the number of nodes in the binary tree pointed to by root? Note: the node that root directly points to should be counted as well as all the ones "underneath" that one.

struct treeNode { int data; treeNode* left; treeNode* right;

) ;

int max(int a,int b) { if          (a > b) return a; return b;

)

int countNodes(struct treeNode* root) {

if (root == NULL) return 0;

/*** insert code ***/

)

a) return countNodes(root->left)*countNodes(root->right);

b) return countNodes(root->left) + countNodes(root->right);

c) return max(countNodes(root->left),countNodes(root->right))+l;

d) return max(countNodes(root->left),countNodes(root->right));

e) None of the Above

8) For a tree with n nodes, what is the average case run-time of the completed function shown in the previous question?

a) 0(1)             b) O(lg n)                     c) O(..fil)                     d) O(n)             e) None of the Above

Explanation / Answer

d

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