Left-Child Right-Sibling Representation is a different representation of an n-ary tree where instead of holding a reference to each and every child node, a node holds just two references, first a reference to it’s first child, and the other to it’s immediate next sibling. This new transformation not only removes the need of advance knowledge of the number of children a node has, but also limits the number of references to a maximum of two, thereby making it so much easier to code.
At each node, link children of same parent from left to right. Parent should be linked with only first child.
Left Child Right Sibling tree representation 10 | 2 -> 3 -> 4 -> 5 | | 6 7 -> 8 -> 9
Prerequisite : Left-Child Right-Sibling Representation of Tree
Below is the implementation.
10 2 3 4 6 5 7 8 9
Level Order Traversal : The above code talks about depth first traversal. We can also do level order traversal of such representation.
10 2 3 4 5 6 7 8 9
This article is contributed by SAKSHI TIWARI. If you like GeeksforGeeks(We know you do!) and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Construct Complete Binary Tree from its Linked List Representation
- Construct Binary Tree from given Parent Array representation
- Convert left-right representation of a binary tree to down-right
- Left-Child Right-Sibling Representation of Tree
- Shortest path between two nodes in array like representation of binary tree
- Construct Binary Tree from String with bracket representation
- Construct Binary Tree from given Parent Array representation | Iterative Approach
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Lowest Common Ancestor in Parent Array Representation
- Convert a Binary Tree into its Mirror Tree
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
- Check if a binary tree is subtree of another binary tree | Set 1
- Convert a given tree to its Sum Tree
- Binary Tree to Binary Search Tree Conversion
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Check if a binary tree is subtree of another binary tree | Set 2
- Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue)
- Check whether a binary tree is a full binary tree or not
- Check whether a binary tree is a complete tree or not | Set 2 (Recursive Solution)