Binary Tree Zigzag Level Order Traversal

Given a binary Tree, write a code to return binary tree zigzag level order traversal of its node’s values. (ie, from left to right, then right to left for the next level and alternate between).

In the screenshot below, We have printed the zigzag traversal of a binary tree. We have printed the values from left to right for the first level. For the second level, we then moved from right to left. Then for the next level, we move from left to right and so on.

Invert Binary Tree

How to Invert Binary Tree or How to convert a binary tree into its mirror tree.

Given a binary tree, we have to write a code to invert it.

Inverting a Binary Tree

Inverting a binary tree means we have to interchange the left and right children of all non-leaf nodes. In simple words, Output is the mirror of the input tree.

Cousins In Binary Tree

How to check if two nodes are cousins in a Binary tree.

Given two values x and y, we have to write a code to check the nodes corresponding to values x and y are cousins or not. All the values in this binary tree are unique.

Two nodes of a binary tree are cousins if they have the same depth, but have different parents.

In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.