VOOZH about

URL: https://www.geeksforgeeks.org/dsa/creating-tree-left-child-right-sibling-representation/

⇱ Creating a tree with Left-Child Right-Sibling Representation - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Creating a tree with Left-Child Right-Sibling Representation

Last Updated : 23 Jul, 2025

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 its first child, and the other to its immediate next sibling. This new transformation not only removes the need for advanced 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.

Examples: 

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. 


Output
 10 2 3 4 6 5 7 8 9

Time Complexity: O(n2), where n is the number of nodes in the tree.
Auxiliary Space: O(n)

Level Order Traversal: The above code talks about depth-first traversal. We can also do level order traversal of such representation.

Implementation:


Output
10 2 3 4 5 6 7 8 9 

Time Complexity: O(n), where n is the number of nodes in the tree.
Auxiliary Space: O(n)

If you like GeeksforGeeks(We know you do!) and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org.  

Comment
Article Tags:
Article Tags: