Connect nodes at the same level in a binary tree - The Coding Shala
Last Updated: 20-Jan-2021 Home >> Interview Questions >> Connect Nodes at the same level in a binary tree In this post, we will learn how to Connect nodes at the same level in a binary tree and will implement its solution in Java. Connect nodes at the same level in a binary tree We have given a perfect binary tree, where each node has an extra pointer called next. The next pointer should point to the node on the right side of it on the same level. This problem is known as connecting nodes at the same level. Given a binary tree: struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL. Example: Given the following perfect binary tree, ...