Write Algorithms for Tree Traversal Techniques


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



Related

Heap Data Structure

Heap Data Structure: Heap data structure is a specialized binary tree based data structure. Heap is a binary tree with special characteristics. In a heap data structure, nodes are arranged based on...

Minimum spanning tree (MST)

Minimum spanning tree (MST) Minimum spanning tree for a weighted graph  G is a spanning tree such that the sum of the weight is less than (or)equal to sum of weights of every other spanning ...

Representation of a Graph ?

Representation of a  graph is the way of storing data values in  memory location as graph data structure. There are two types  of graph representation techniques. 1. Adjacency ma...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item