Question: code in c + + for the following question There is a binary tree given to you. Each of the nodes represents a student in

code in c++ for the following question
There is a binary tree given to you. Each of the nodes represents a student in the class. You are playing a game where you need to team up with one of the students in class. The team can be formed in such a way that in a team, both students can't have the same parent in the tree and should be at the same level in the binary tree.
Input: We have given you some pairs of students. You need to find out whether the team is valid or not.
Output: 'Yes' if the team is valid or 'No' if the team is invalid.
Page 2
(a) Optimal solution of O(n) for checking the team validity.
(b) How many tree traversals are required to solve the above problem?
Example Input :
Target Node : 14
Input: 121310 N N 1415 N N N N 21242223(Level order input)
Query 1: 24 and 22
Output 1: Yes
Query 2: 14 and 15
Output 2: No
For query 1: 24 and 22 are at the same level but don't have the same parent.
For query 2: 14 and 15 both have the same parent.
code in c + + for the following question There 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 Programming Questions!