Left-Child Right-Sibling Representation of Tree

Data Structure AlgorithmsAnalysis of AlgorithmsAlgorithms

Left-Child Right-Sibling Representation is a different representation of an n-ary tree where instead of maintaining a pointer to each and every child node, a node holds just two pointers, first a pointer to its first child, and the other pointer to its immediate next sibling. This new transformation not only eliminates the need of prior knowledge of the number of children a node has, but also restricts the number of pointers to a maximum of two, so making it so much simpler to code.

At each node, link or connect 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

Advantages

  • This representation saves up memory by restricting the maximum number of pointers required per node to two.
  • It is simpler to code.

Disadvantages

  • Basic operations like searching/insertion/deletion consume longer time because in order to select the exact position we would have to traverse through all the siblings of the node to be searched/inserted/deleted (according to the worst case).
raja
Published on 02-Jan-2020 06:36:47
Advertisements