Construct LCRS Binary Tree Problem

Vivek Srivastava
Techie Delight

--

Given the root of a binary tree, convert it into a Left–child right–sibling (LC–RS) binary tree.

Each node in the LC–RS binary tree has two pointers: one to the node’s left child and one to its next sibling in the original binary tree. So starting with the root, each node’s leftmost child in the original tree is made its left child in the LC–RS binary tree, and its nearest sibling to the right in the original tree is made its right child in the binary tree.

For example, we have a binary tree below:

a. Processing binary tree to LC–RS binary tree, every node is linked and aligned with the left child, and the next nearest is a sibling.

b. We can rewrite the binary tree shown by putting the left child node to one level below its parents and by placing the sibling next to the left child at the same level.

c. We can transform this tree into a LC-RS binary tree by turning each sibling 45° clockwise.

Practice link: https://www.techiedelight.com/?problem=ConstructLCRSBinaryTree

--

--