yesiamrajeev / Hacktoberfest2024

Do contribute to this repository and gain experience. Happy-Hacking.
16 stars 65 forks source link

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

Open simran0963 opened 1 day ago

simran0963 commented 1 day ago

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.