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

Here are the questions: template <typename T> int ct2 (tnode<T> *t) { int ctLeft

ID: 3539710 • Letter: H

Question

Here are the questions:



template <typename T>

int ct2 (tnode<T> *t)

{

   int ctLeft, ctRight, ct;

   if (t == NULL)

   ct = 0;

   else

   {

     ctLeft= ct2(t->left);

     ctRight= ct2(t->right);

     ct = ctLeft + ctRight +

((t->left != NULL && t->right != NULL) ? 1 : 0);

   }

   return ct;

}



template<typename T>

T& stree<T>::f()

{

     stnode<T> *t = root;

     while (t->right != NULL)

           t = t->right;

     return t->nodeValue;

}


Nodes in a binary tree that have only NULL children are called ______________________________.


The longest path length from the root to a node is called the __________________ of the tree.


template <typename T>

int treeFunc(tnode<T> *t)

{    int n = 0, left, right;

     if (t != NULL)

     { if (t->left != NULL)

                n++;

           if (t->right != NULL)

                n++;

           left = treeFunc(t->left);

           right = treeFunc(t->right);

           return   n + left + right;

     }

     else

           return 0;

}

1. Trace the function ct2() and describe its action.


template <typename T>

int ct2 (tnode<T> *t)

{

   int ctLeft, ctRight, ct;

   if (t == NULL)

   ct = 0;

   else

   {

     ctLeft= ct2(t->left);

     ctRight= ct2(t->right);

     ct = ctLeft + ctRight +

((t->left != NULL && t->right != NULL) ? 1 : 0);

   }

   return ct;

}



(Points : 8)       
      

Explanation / Answer

1.Gives the sum of all the numbers int binary tree from taking the root of the tree as t initially.


template <typename T>

int ct2 (tnode<T> *t) //function declaration a node enters here

{

   int ctLeft, ctRight, ct;

   if (t == NULL)

//If the entered value is a leafe node we will return 0

   ct = 0;

   else

   {

//calling the left subtree

     ctLeft= ct2(t->left);

//calling the right subtree

     ctRight= ct2(t->right);

//adding the left +right sum to get the total sum

     ct = ctLeft + ctRight +

((t->left != NULL && t->right != NULL) ? 1 : 0);

   }

//returning the final value

   return ct;

}

2. 2 3 4 7 8 9 11

3.Gives the right most value.(The maximum value)

4.Leafe nodes

5.Depth of the tree

6. identifies the number of nodes in the tree

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