You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a code in c++ which checks if the 2 nodes provided in a binary tree are cousins or not. This uses tree traversal technique i.e., dfs to traverse the binary tree and determines the parent for both the nodes. It also check the levels the two nodes are in. And if they turn out to be cousins then it returns true, else returns false.
Important point to note is that cousins sould be present in the same level no matter what.
If two nodes have different levels then they cannot be cousins
And all nodes on the same level are not cousins, as cousins need to have different parents. If the two nodes are present in the same level but also have same parents, then also they are not considered to be cousins.
Please mark the hacktoberfest and hacktoberfest-accepted labels upon approving and merging the request.
The text was updated successfully, but these errors were encountered:
I added a code in c++ which checks if the 2 nodes provided in a binary tree are cousins or not. This uses tree traversal technique i.e., dfs to traverse the binary tree and determines the parent for both the nodes. It also check the levels the two nodes are in. And if they turn out to be cousins then it returns true, else returns false.
Important point to note is that cousins sould be present in the same level no matter what.
If two nodes have different levels then they cannot be cousins
And all nodes on the same level are not cousins, as cousins need to have different parents. If the two nodes are present in the same level but also have same parents, then also they are not considered to be cousins.
Please mark the hacktoberfest and hacktoberfest-accepted labels upon approving and merging the request.
The text was updated successfully, but these errors were encountered: