Preorder traversal:
preorder(v)
if(v==NULL) then return
else visit(v)//generic computation
preorder(v.leftchild())
preorder(v.rightchild())
postorder(v)
if(v==NULL) then return
else postorder(v.leftchild())
postorder(v.rightchild())
visit(v)//generic computation
Use of post order traversal:
->computing arithmetic expression
Inorder traversal:When the node is visited between the left
and the right subtree(only in binary tree)
inOrder(v):
if(v==NULL)then return
else inOrder(v.leftChild())
visit(v)
inOrder(v.rightChild())
Another way is the Euler Tour traversal:
->generic traversal of the binary tree.
->Each case is a special case of this tree
->Each internal node is visited three times
->Given the preorder and the inorder traversal of a binary tree
we can find out the actual tree recursively.
->Similarly we can find the tree from post order and inorder
traversal mentioned.
->But a postorder and a preorder traversal is insufficient as
there can be two trees having the same preorder and post order
traversal
->however in case of binary tree we can make the tree given the preorder and the post order traversal
Next entries will be:
1. Program to print the tree given:
->postorder and inorder traversal
->preorder and inorder traversal
->postorder and preorder traversal in binary tree
2. To compute the number of possible trees given a particular
order of binary tree
preorder(v)
if(v==NULL) then return
else visit(v)//generic computation
preorder(v.leftchild())
preorder(v.rightchild())
postorder(v)
if(v==NULL) then return
else postorder(v.leftchild())
postorder(v.rightchild())
visit(v)//generic computation
Use of post order traversal:
->computing arithmetic expression
Inorder traversal:When the node is visited between the left
and the right subtree(only in binary tree)
inOrder(v):
if(v==NULL)then return
else inOrder(v.leftChild())
visit(v)
inOrder(v.rightChild())
Another way is the Euler Tour traversal:
->generic traversal of the binary tree.
->Each case is a special case of this tree
->Each internal node is visited three times
->Given the preorder and the inorder traversal of a binary tree
we can find out the actual tree recursively.
->Similarly we can find the tree from post order and inorder
traversal mentioned.
->But a postorder and a preorder traversal is insufficient as
there can be two trees having the same preorder and post order
traversal
->however in case of binary tree we can make the tree given the preorder and the post order traversal
Next entries will be:
1. Program to print the tree given:
->postorder and inorder traversal
->preorder and inorder traversal
->postorder and preorder traversal in binary tree
2. To compute the number of possible trees given a particular
order of binary tree