Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add code to check cousins in a binary tree implemented using c++ #96

Open
simran0963 opened this issue Oct 23, 2024 · 0 comments
Open
Assignees
Labels
hacktoberfest2024 Hacktoberfest hacktoberfest-accepted Hacktoberfest2024

Comments

@simran0963
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest2024 Hacktoberfest hacktoberfest-accepted Hacktoberfest2024
Projects
None yet
Development

No branches or pull requests

2 participants