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 email@example.com. 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.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Convert left-right representation of a binary tree to down-right
- Left-Child Right-Sibling Representation of Tree
- Construct Binary Tree from given Parent Array representation
- Construct Binary Tree from String with bracket representation
- Construct Complete Binary Tree from its Linked List Representation
- Shortest path between two nodes in array like representation of binary tree
- Construct Binary Tree from given Parent Array representation | Iterative Approach
- Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST
- Lowest Common Ancestor in Parent Array Representation
- Complexity of different operations in Binary tree, Binary Search Tree and AVL tree
- Given level order traversal of a Binary Tree, check if the Tree is a Min-Heap
- Convert an arbitrary Binary Tree to a tree that holds Children Sum Property
- Print Binary Tree levels in sorted order | Set 3 (Tree given as array)
- Check if a given Binary Tree is height balanced like a Red-Black Tree
- Convert a given Binary tree to a tree that holds Logical AND property