Algorithm for tree traversal / traversing a tree
Algorithm:
Step1: Start Step2: Assign 1 to root node Assign 2 to left subtree Assign 3 to right subtree Assign 4 to left of left subtree Assign 5 to right of left subtree Step3: Perform printpreorder() Step4: Perform printinorder() Step5: Perform printpostorder() Step6: print preorder function 1.if node=null,then return 2.Traverse the root node 3.Traverse the left subtree 4.Traverse the right subtree printinorder function 1.if node=null,then return 2.Traverse the left subtree 3.Visit the root node 4.Traverse the right subtree printpostorder function 1.if node=null,then return 2.Traverse the left subtree 3.Traverse the right subtree 4.Visit the root node Step7:stop
Comments
Post a Comment