Saturday, June 19, 2021
Home coding Write a program to traverse tree using postorder traversal.

Write a program to traverse tree using postorder traversal.

Given a tree ,we have to traverse a tree using PostOrder traversal and print the result.

So what is PostOrder Traversal?

In this traversal we follow left,right,root approach.

Logic:

step 1- traverse left subtree .
step 2- traverse right subtree.
step 3- then print root value.

void Postorder(node *root)
{
if(root==NULL)
{
return;
}
Postorder(root->left);
Postorder(root->right);
cout<<root->data<<" ";

}

Time Complexity:O(N)

Space Complexity:O(N)

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments