Write Algorithms for Tree Traversal Techniques
https://www.computersprofessor.com/2016/11/write-algorithms-for-tree-traversal.html
Algorithms for Tree Traversal Techniques:
Algorithm for Preorder :This is recursive process according to this traversal
technique 1st visits the root node then visit the left sub tree then
it visits the right sub tree. For every child it repeats the same process.
Input : p -> root
Output :
visiting all nodes from begin .
if(p!=null) then
visit(p)
preorder (p. left)
preorder (p.right)
end if
end
In this traversal it first visits
the left sub tree and root and then the right sub tree. This process is repeated
by every node.
Algorithm for Inorder :
Input : p -> root
Output :visiting
all nodes from begin
if (p! = null) then
inorder (p. left)
visit(p)
inorder (p.right)
end if
end.
Algorithm for Post order :This traversal technique visits all the nodes of binary
tree in the following way. It first visits the left sub tree of root node and
the right sub tree of the root node and finally the root node . This process is
repeated recursively for each and every node in the tree.
Input :p¬->root
Output :
visiting all nodes from begin
if(p! =null) then
postorder( p. left)
postorder( p. right)
visit(p)
end if
end