Thursday, June 24, 2021
Home coding Write a program to traverse tree using Inorder traversal.

Write a program to traverse tree using Inorder traversal.

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

So what is Inorder Traversal?

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

Logic:

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

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

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