Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Given a binary tree, Print All the Nodes that don’t have Siblings.

Objec­tive: Given a binary tree, Print All the Nodes that don’t have siblings.

Note: sib­ling node is the node which has the same par­ent, so you need to print the nodes who is a sin­gle child of his parent.

Input: A binary tree.

Exam­ple:

Print All the Nodes that don't have siblings.

Print All the Nodes that don’t have siblings.

Approach:

  • Do the inorder traversal.
  • check if node has only child, if yes then print that child.

Com­plete Code:


Out­put:

Nodes with No Siblings: 6 7 8 9

 

 

You may also like...

  • Kamal Chaya

    Why do we have to do in order tra­ver­sal? won’t pre order work?