Answer to Question #242325 in C for Asjad

Question #242325

2. There is a binary tree given to you. In which each of the node represents the student in the class. You are playing a game in which you need to team up with one of student in class. Team can be formed in such a way that in a team both of the students can’t have same parent in tree and should be at the same level in binary tree. The number of students in the class is denoted by ‘n’. The value will be user-defined.

Input: we have given you some pair of students you need to find that is the team valid or not.

Output: ‘Yes’ if the team is valid or ‘No’ if the team is invalid.

Also, Find

(a) How many tree traversal is required for the solution of the above problem


1
Expert's answer
2021-09-26T11:42:05-0400
class Node
{
    int key;
    Node left, right;
 
    public Node(int item)
    {
        key = item;
        left = right = null;
    }
}
 
class BinaryTree
{
    Node root;
    BinaryTree(int key)
    {
        root = new Node(key);
    }
 
    BinaryTree()
    {
        root = null;
    }
 
    public static void main(String[] args)
    {
        BinaryTree tree = new BinaryTree();
        tree.root = new Node(1);
 
        tree.root.left = new Node(2);
        tree.root.right = new Node(3);

        tree.root.left.left = new Node(4);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS