In which order the given tree will Travers when we use the following: i) Post order Traversal ii) Write down the code for the Post Order Traversal of any tree | PU | Past Paper 2017

UNIVERSITY OF THE PUNJAB

Fourth Semester 2017

Examination: B.S. 4 Years Programme 

Paper: Data Structure and Algorithm

Course Code: IT-207 / IT-22408

Long Questions

c) In which order the given tree will Travers when we use the following:

i) Post order Traversal

ii) Write down the code for the Post Order Traversal of any tree.

void PostOrderTraversal (Node* root); //it is the prototype of the function which you have to define.


i) Post order Traversal

(L,R,N)
(Left Node, Right Node, Root Node)

void PostOrderTraversal (Node* root);

void postorder(treeNode* treeNode)
{
    if( treeNode != NULL ) 
    {
        postorder(treeNode->getLeft());
        postorder(treeNode->getRight());
        cout << treeNode->getInfo()<<" ";
    }
}

Let me know in the comment section if you have any question.

Previous Post:
Suppose you are given a sorted array A of n distinct numbers that has been rotated k steps, for some unknown integer k between 1 to n-1. You have to design an O(nlogn) code to find the value of k | PU | Past Paper 2017



Comments