Question

(30 pt) Give Recursive Pseudocode for how one might calculate the height of a First Child,...

  1. (30 pt) Give Recursive Pseudocode for how one might calculate the height of a First Child, Next Sibling Tree. To be clear, you cannot call a regular Binary tree height algorithm – siblings are at the same “depth”. Assume Nodes defined as:
    struct Node{

    int val;
    Node* child; Node* sibling;

    };

Homework Answers

Answer #1

struct Node{

int val;
Node* child; Node* sibling;

};

int height(Node* root)
{
    if (root == NULL)
        return 0;
  
   int maxHeight = 0;  
   Node* current = root->child;
   while (current != NULL)
    {
        int h = height(current);
        current = current->sibling;
        if(h > maxHeight) maxHeight = h;
    }
    return maxHeight + 1;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions