Write an efficient algorithm to find that given two binary nodes are cousin or not.
Condition of cousin nodes.
1) nodes are exist in same level.
2) parent nodes are not same at given nodes.
Suppose following nodes are inserted on binary tree.
Hint: solve this problem by using a queue.
View nodes and pointers.
Try it Yourself
Program for check if two given nodes are cousins in binary tree. iterative solution using queue.
Visualize process Try it Yourself