This post is completed by 1 user

  • 0
Add to List
Hard

137. Populate Next Right Pointers in Each Node

Objective: - Given a binary tree with three-pointers left, right, and next Sibling). Write the program to provide the next sibling pointers.

This problem can also be referred to as Populate Next Siblings Pointers in a Given Binary Tree

Example:

Provide the Next Siblings Pointers in a Given Binary Tree.

Approach:

  • Use Recursion.
  • Start from the root
    • If the root's left node is not null, make it point to the root's right child
    • If the root's next sibling is not null, make the next sibling of the root's right node point  to the root's next sibling's left child (In our example node 5 points to node 6, as per our statement, the Parent of node 5 is node 2, the next sibling of node 2 is node 3, and the left child of node 2 is node 6, So Node 5 will point to Node 6 )
 
1
2 3
4 5 6 7