Open In App

Print Postorder traversal from given Inorder and Preorder traversals

Last Updated : 18 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

AuxiliaryGiven Inorder and Preorder traversals of a binary tree, print Postorder traversal.

Example:

Input:
Inorder traversal in[] = {4, 2, 5, 1, 3, 6}
Preorder traversal pre[] = {1, 2, 4, 5, 3, 6}

Output:
Postorder traversal is {4, 5, 2, 6, 3, 1}

Traversals in the above example represents following tree 

         1
      /    \    
     2       3
   /   \      \
  4     5      6

A naive method is to first construct the tree, then use a simple recursive method to print postorder traversal of the constructed tree.

We can print postorder traversal without constructing the tree. The idea is, root is always the first item in preorder traversal and it must be the last item in postorder traversal. We first recursively print left subtree, then recursively print right subtree. Finally, print root. 

To find boundaries of left and right subtrees in pre[] and in[], we search root in in[], all elements before root in in[] are elements of left subtree, and all elements after root are elements of right subtree. In pre[], all elements after index of root in in[] are elements of right subtree. And elements before index (including the element at index and excluding the first element) are elements of left subtree.

Implementation:

C++




// C++ program to print postorder traversal
// from preorder and inorder traversals
#include <iostream>
using namespace std;
 
// A utility function to search x in arr[] of size n
int search(int arr[], int x, int n)
{
    for (int i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}
 
// Prints postorder traversal from given
// inorder and preorder traversals
void printPostOrder(int in[], int pre[], int n)
{
    // The first element in pre[] is always root, search it
    // in in[] to find left and right subtrees
    int root = search(in, pre[0], n);
 
    // If left subtree is not empty, print left subtree
    if (root != 0)
        printPostOrder(in, pre + 1, root);
 
    // If right subtree is not empty, print right subtree
    if (root != n - 1)
        printPostOrder(in + root + 1, pre + root + 1, n - root - 1);
 
    // Print root
    cout << pre[0] << " ";
}
 
// Driver program to test above functions
int main()
{
    int in[] = { 4, 2, 5, 1, 3, 6 };
    int pre[] = { 1, 2, 4, 5, 3, 6 };
    int n = sizeof(in) / sizeof(in[0]);
    cout << "Postorder traversal " << endl;
    printPostOrder(in, pre, n);
    return 0;
}


Java




// Java program to print postorder
// traversal from preorder and
// inorder traversals
import java.util.Arrays;
 
class GFG
{
 
// A utility function to search x in arr[] of size n
static int search(int arr[], int x, int n)
{
    for (int i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}
 
// Prints postorder traversal from
// given inorder and preorder traversals
static void printPostOrder(int in1[],
                    int pre[], int n)
{
    // The first element in pre[] is
    // always root, search it in in[]
    // to find left and right subtrees
    int root = search(in1, pre[0], n);
 
    // If left subtree is not empty,
    // print left subtree
    if (root != 0)
        printPostOrder(in1, Arrays.copyOfRange(pre, 1, n), root);
 
    // If right subtree is not empty,
    // print right subtree
    if (root != n - 1)
        printPostOrder(Arrays.copyOfRange(in1, root+1, n),
            Arrays.copyOfRange(pre, 1+root, n), n - root - 1);
 
    // Print root
    System.out.print( pre[0] + " ");
}
 
// Driver code
public static void main(String args[])
{
    int in1[] = { 4, 2, 5, 1, 3, 6 };
    int pre[] = { 1, 2, 4, 5, 3, 6 };
    int n = in1.length;
    System.out.println("Postorder traversal " );
    printPostOrder(in1, pre, n);
}
}
// This code is contributed by Arnab Kundu


Python3




# Python3 program to print postorder
# traversal from preorder and inorder
# traversals
 
# A utility function to search x in
# arr[] of size n
def search(arr, x, n):
      
    for i in range(n):
        if (arr[i] == x):
            return i
 
    return -1
 
# Prints postorder traversal from
# given inorder and preorder traversals
def printPostOrder(In, pre, n):
     
    # The first element in pre[] is always
    # root, search it in in[] to find left
    # and right subtrees
    root = search(In, pre[0], n)
 
    # If left subtree is not empty,
    # print left subtree
    if (root != 0):
        printPostOrder(In, pre[1:n], root)
 
    # If right subtree is not empty,
    # print right subtree
    if (root != n - 1):
        printPostOrder(In[root + 1 : n],
                      pre[root + 1 : n],
                      n - root - 1)
 
    # Print root
    print(pre[0], end = " ")
 
# Driver code
In = [ 4, 2, 5, 1, 3, 6 ]
pre = [ 1, 2, 4, 5, 3, 6 ]
n = len(In)
 
print("Postorder traversal ")
 
printPostOrder(In, pre, n)
 
# This code is contributed by avanitrachhadiya2155


C#




// C# program to print postorder
// traversal from preorder and
// inorder traversals
using System;
 
class GFG
{
 
// A utility function to search x
// in []arr of size n
static int search(int []arr,
                  int x, int n)
{
    for (int i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}
 
// Prints postorder traversal from
// given inorder and preorder traversals
static void printPostOrder(int []in1,
                    int []pre, int n)
{
    // The first element in pre[] is
    // always root, search it in in[]
    // to find left and right subtrees
    int root = search(in1, pre[0], n);
 
    // If left subtree is not empty,
    // print left subtree
    int []ar;
    if (root != 0)
    {
        ar = new int[n - 1];
        Array.Copy(pre, 1, ar, 0, n - 1);
        printPostOrder(in1, ar, root);
    }
     
    // If right subtree is not empty,
    // print right subtree
    if (root != n - 1)
    {
        ar = new int[n - (root + 1)];
        Array.Copy(in1, root + 1, ar, 0,
                        n - (root + 1));
        int []ar1 = new int[n - (root + 1)];
        Array.Copy(pre, root + 1, ar1, 0,
                         n - (root + 1));
        printPostOrder(ar, ar1, n - root - 1);
    }
     
    // Print root
    Console.Write(pre[0] + " ");
}
 
// Driver code
public static void Main(String []args)
{
    int []in1 = { 4, 2, 5, 1, 3, 6 };
    int []pre = { 1, 2, 4, 5, 3, 6 };
    int n = in1.Length;
    Console.WriteLine("Postorder traversal " );
    printPostOrder(in1, pre, n);
}
}
 
// This code is contributed by 29AjayKumar


Javascript




<script>
 
// javascript program to print postorder
// traversal from preorder and
// inorder traversals
 
// A utility function to search x in arr of size n
function search(arr , x , n)
{
    for (var i = 0; i < n; i++)
        if (arr[i] == x)
            return i;
    return -1;
}
 
// Prints postorder traversal from
// given inorder and preorder traversals
function printPostOrder( in1,
                    pre , n)
{
    // The first element in pre is
    // always root, search it in in
    // to find left and right subtrees
    var root = search(in1, pre[0], n);
 
    // If left subtree is not empty,
    // print left subtree
    if (root != 0)
        printPostOrder(in1, pre.slice(1, n), root);
 
    // If right subtree is not empty,
    // print right subtree
    if (root != n - 1)
        printPostOrder(in1.slice(root+1, n),
            pre.slice(1+root, n), n - root - 1);
 
    // Print root
    document.write( pre[0] + " ");
}
 
// Driver code
var in1 = [ 4, 2, 5, 1, 3, 6 ];
var pre = [ 1, 2, 4, 5, 3, 6 ];
var n = in1.length;
document.write("Postorder traversal <br>" );
printPostOrder(in1, pre, n);
 
// This code contributed by shikhasingrajput
</script>


Output

Postorder traversal 
4 5 2 6 3 1 

Time Complexity: O(N), where N is the number of nodes in the binary tree. We process every node once, so the time complexity is linear.
Auxiliary Space: O(N). We need to store the recursive calls in the system stack, and in the worst case, the tree is skewed and the height is N. So we need O(N) space for the system stack.

Implementation:

C++




// C++ program to print Postorder
// traversal from given Inorder
// and Preorder traversals.
#include <iostream>
using namespace std;
 
int preIndex = 0;
 
int search(int arr[], int startIn,int endIn, int data)
{
    int i = 0;
    for (i = startIn; i < endIn; i++)
    {
        if (arr[i] == data)
        {
            return i;
        }
    }
    return i;
}
void printPost(int arr[], int pre[],int inStrt, int inEnd)
{
    if (inStrt > inEnd)
    {
        return;
    }
 
    // Find index of next item in preorder
    // traversal in inorder.
    int inIndex = search(arr, inStrt, inEnd,pre[preIndex++]);
 
    // traverse left tree
    printPost(arr, pre, inStrt, inIndex - 1);
 
    // traverse right tree
    printPost(arr, pre, inIndex + 1, inEnd);
 
    // print root node at the end of traversal
    cout << arr[inIndex] << " ";
}
 
// Driver code
int main()
{
    int arr[] = {4, 2, 5, 1, 3, 6};
    int pre[] = {1, 2, 4, 5, 3, 6};
    int len = sizeof(arr)/sizeof(arr[0]);
    printPost(arr, pre, 0, len - 1);
}
 
// This code is contributed by SHUBHAMSINGH10


Java




// Java program to print Postorder traversal from given Inorder
// and Preorder traversals.
 
public class PrintPost {
    static int preIndex = 0;
    void printPost(int[] in, int[] pre, int inStrt, int inEnd)
    {
        if (inStrt > inEnd)
            return;       
 
        // Find index of next item in preorder traversal in
        // inorder.
        int inIndex = search(in, inStrt, inEnd, pre[preIndex++]);
 
        // traverse left tree
        printPost(in, pre, inStrt, inIndex - 1);
 
        // traverse right tree
        printPost(in, pre, inIndex + 1, inEnd);
 
        // print root node at the end of traversal
        System.out.print(in[inIndex] + " ");
    }
 
    int search(int[] in, int startIn, int endIn, int data)
    {
        int i = 0;
        for (i = startIn; i < endIn; i++)
            if (in[i] == data)
                return i;           
        return i;
    }
 
    // Driver code
    public static void main(String ars[])
    {
        int in[] = { 4, 2, 5, 1, 3, 6 };
        int pre[] = { 1, 2, 4, 5, 3, 6 };
        int len = in.length;
        PrintPost tree = new PrintPost();
        tree.printPost(in, pre, 0, len - 1);
    }
}


Python3




# Python3 program to print Postorder
# traversal from given Inorder
# and Preorder traversals.
preIndex = 0
 
def search(arr, startIn, endIn, data):
    i = 0
    for i in range(startIn, endIn+1):
        if (arr[i] == data):
            return i
    return i
 
def printPost(arr, pre, inStrt, inEnd):
    if (inStrt > inEnd):
        return
 
    # Find index of next item in preorder
    # traversal in inorder.
    global preIndex
    preIndex += 1
    inIndex = search(arr, inStrt, inEnd, pre[preIndex-1])
 
    # traverse left tree
    printPost(arr, pre, inStrt, inIndex - 1)
 
    # traverse right tree
    printPost(arr, pre, inIndex + 1, inEnd)
 
    # print root node at the end of traversal
    print(arr[inIndex], end=" ")
 
# Driver code
arr = [4, 2, 5, 1, 3, 6]
pre = [1, 2, 4, 5, 3, 6]
len = len(arr)
printPost(arr, pre, 0, len-1)
 
# This code is contributed by Abhijeet Kumar(abhijeet19403)


C#




// C# program to print Postorder
// traversal from given Inorder
// and Preorder traversals.
using System;
 
class GFG
{
public static int preIndex = 0;
public virtual void printPost(int[] arr, int[] pre,
                              int inStrt, int inEnd)
{
    if (inStrt > inEnd)
    {
        return;
    }
 
    // Find index of next item in preorder
    // traversal in inorder.
    int inIndex = search(arr, inStrt, inEnd,
                         pre[preIndex++]);
 
    // traverse left tree
    printPost(arr, pre, inStrt, inIndex - 1);
 
    // traverse right tree
    printPost(arr, pre, inIndex + 1, inEnd);
 
    // print root node at the end of traversal
    Console.Write(arr[inIndex] + " ");
}
 
public virtual int search(int[] arr, int startIn,
                          int endIn, int data)
{
    int i = 0;
    for (i = startIn; i < endIn; i++)
    {
        if (arr[i] == data)
        {
            return i;
        }
    }
    return i;
}
 
// Driver code
public static void Main(string[] ars)
{
    int[] arr = new int[] {4, 2, 5, 1, 3, 6};
    int[] pre = new int[] {1, 2, 4, 5, 3, 6};
    int len = arr.Length;
    GFG tree = new GFG();
    tree.printPost(arr, pre, 0, len - 1);
}
}
 
// This code is contributed by Shrikant13


Javascript




<script>
 
      // JavaScript program to print Postorder
      // traversal from given Inorder
      // and Preorder traversals.
      class GFG {
        constructor() {
          this.preIndex = 0;
        }
        printPost(arr, pre, inStrt, inEnd) {
          if (inStrt > inEnd) {
            return;
          }
 
          // Find index of next item in preorder
          // traversal in inorder.
          var inIndex = this.search(arr, inStrt, inEnd,
          pre[this.preIndex++]);
 
          // traverse left tree
          this.printPost(arr, pre, inStrt, inIndex - 1);
 
          // traverse right tree
          this.printPost(arr, pre, inIndex + 1, inEnd);
 
          // print root node at the end of traversal
          document.write(arr[inIndex] + " ");
        }
 
        search(arr, startIn, endIn, data) {
          var i = 0;
          for (i = startIn; i < endIn; i++) {
            if (arr[i] == data) {
              return i;
            }
          }
          return i;
        }
      }
      // Driver code
      var arr = [4, 2, 5, 1, 3, 6];
      var pre = [1, 2, 4, 5, 3, 6];
      var len = arr.length;
      var tree = new GFG();
      tree.printPost(arr, pre, 0, len - 1);
       
</script>


Output: 

4 5 2 6 3 1

 

Time Complexity: The above function visits every node in the array. For every visit, it calls search which takes O(n) time. Therefore, overall time complexity of the function is O(n2)
Auxiliary Space: O(1)

 

Implementation: The above solution can be optimized using hashing. We use a HashMap to store elements and their indexes so that we can quickly find the index of an element. 

C++




// C++ program to print Postorder traversal from
// given Inorder and Preorder traversals.
#include<bits/stdc++.h>
using namespace std;
 
int preIndex = 0;
void printPost(int in[], int pre[], int inStrt,
               int inEnd, map<int, int> hm)
{
    if (inStrt > inEnd)
        return;        
 
    // Find index of next item in preorder traversal in
    // inorder.
    int inIndex = hm[pre[preIndex++]];
 
    // traverse left tree
    printPost(in, pre, inStrt, inIndex - 1, hm);
 
    // traverse right tree
    printPost(in, pre, inIndex + 1, inEnd, hm);
 
    // print root node at the end of traversal
    cout << in[inIndex] << " ";
}
 
void printPostMain(int in[], int pre[],int n)
{
    map<int,int> hm ;
    for (int i = 0; i < n; i++)
    hm[in[i]] = i;
         
    printPost(in, pre, 0, n - 1, hm);
}
 
// Driver code
int main()
{
    int in[] = { 4, 2, 5, 1, 3, 6 };
    int pre[] = { 1, 2, 4, 5, 3, 6 };
    int n = sizeof(pre)/sizeof(pre[0]);
     
    printPostMain(in, pre, n);
    return 0;
}
 
// This code is contributed by Arnab Kundu


Java




// Java program to print Postorder traversal from
// given Inorder and Preorder traversals.
import java.util.*;
 
public class PrintPost {
    static int preIndex = 0;
    void printPost(int[] in, int[] pre, int inStrt,
               int inEnd, HashMap<Integer, Integer> hm)
    {
        if (inStrt > inEnd)
            return;        
 
        // Find index of next item in preorder traversal in
        // inorder.
        int inIndex = hm.get(pre[preIndex++]);
 
        // traverse left tree
        printPost(in, pre, inStrt, inIndex - 1, hm);
 
        // traverse right tree
        printPost(in, pre, inIndex + 1, inEnd, hm);
 
        // print root node at the end of traversal
        System.out.print(in[inIndex] + " ");
    }
 
    void printPostMain(int[] in, int[] pre)
    {
        int n = pre.length;
        HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
        for (int i=0; i<n; i++)
           hm.put(in[i], i);
            
        printPost(in, pre, 0, n-1, hm);
    }
 
    // Driver code
    public static void main(String ars[])
    {
        int in[] = { 4, 2, 5, 1, 3, 6 };
        int pre[] = { 1, 2, 4, 5, 3, 6 };
        PrintPost tree = new PrintPost();
        tree.printPostMain(in, pre);
    }
}


Python3




# Python3 program to print Postorder traversal from
# given Inorder and Preorder traversals.
 
def printPost(inn, pre, inStrt, inEnd):
    global preIndex, hm
    if (inStrt > inEnd):
        return
 
    # Find index of next item in preorder traversal in
    # inorder.
    inIndex = hm[pre[preIndex]]
    preIndex += 1
 
    # traverse left tree
    printPost(inn, pre, inStrt, inIndex - 1)
 
    # traverse right tree
    printPost(inn, pre, inIndex + 1, inEnd)
 
    # print root node at the end of traversal
    print(inn[inIndex], end = " ")
 
def printPostMain(inn, pre, n):
 
    for i in range(n):
        hm[inn[i]] = i
 
    printPost(inn, pre, 0, n - 1)
 
# Driver code
if __name__ == '__main__':
    hm = {}
    preIndex = 0
    inn = [4, 2, 5, 1, 3, 6]
    pre = [1, 2, 4, 5, 3, 6]
 
    n = len(pre)
 
    printPostMain(inn, pre, n)
 
# This code is contributed by mohit kumar 29


C#




// C# program to print Postorder
// traversal from given Inorder
// and Preorder traversals.
using System;
 
class GFG
{
public static int preIndex = 0;
public virtual void printPost(int[] arr, int[] pre,
                              int inStrt, int inEnd)
{
    if (inStrt > inEnd)
    {
        return;
    }
 
    // Find index of next item in preorder
    // traversal in inorder.
    int inIndex = search(arr, inStrt, inEnd,
                         pre[preIndex++]);
 
    // traverse left tree
    printPost(arr, pre, inStrt, inIndex - 1);
 
    // traverse right tree
    printPost(arr, pre, inIndex + 1, inEnd);
 
    // print root node at the
    // end of traversal
    Console.Write(arr[inIndex] + " ");
}
 
public virtual int search(int[] arr, int startIn,
                          int endIn, int data)
{
    int i = 0;
    for (i = startIn; i < endIn; i++)
    {
        if (arr[i] == data)
        {
            return i;
        }
    }
    return i;
}
 
// Driver code
public static void Main(string[] ars)
{
    int[] arr = new int[] {4, 2, 5, 1, 3, 6};
    int[] pre = new int[] {1, 2, 4, 5, 3, 6};
    int len = arr.Length;
    GFG tree = new GFG();
    tree.printPost(arr, pre, 0, len - 1);
}
}
 
// This code is contributed by Shrikant13


Javascript




<script>
 
// Javascript program to print
// Postorder traversal from given
// Inorder and Preorder traversals.
let preIndex = 0;
 
function printPost(In, pre, inStrt, inEnd, hm)
{
    if (inStrt > inEnd)
        return;       
 
    // Find index of next item in
    // preorder traversal in inorder.
    let inIndex = hm.get(pre[preIndex++]);
 
    // Traverse left tree
    printPost(In, pre, inStrt, inIndex - 1, hm);
 
    // Traverse right tree
    printPost(In, pre, inIndex + 1, inEnd, hm);
 
    // Print root node at the end of traversal
    document.write(In[inIndex] + " ");
}
 
function printPostMain(In, pre)
{
    let n = pre.length;
    let hm = new Map();
     
    for(let i = 0; i < n; i++)
       hm.set(In[i], i);
        
    printPost(In, pre, 0, n - 1, hm);
}
 
// Driver code
let In = [ 4, 2, 5, 1, 3, 6 ];
let pre = [ 1, 2, 4, 5, 3, 6 ];
 
printPostMain(In, pre);
 
// This code is contributed by unknown2108
 
</script>


Output

4 5 2 6 3 1 

Time complexity: O(n) 
Auxiliary Space : O(n)



Similar Reads

Check if given Preorder, Inorder and Postorder traversals are of same tree | Set 2
Given Preorder, Inorder and Postorder traversals of some tree. The task is to check if they all are of the same tree.Examples: Input : Inorder -&gt; 4 2 5 1 3 Preorder -&gt; 1 2 4 5 3 Postorder -&gt; 4 5 2 3 1 Output : Yes Explanation : All of the above three traversals are of the same tree. 1 / \ 2 3 / \ 4 5 Input : Inorder -&gt; 4 2 5 1 3 Preorde
11 min read
Check if given Preorder, Inorder and Postorder traversals are of same tree
Given Preorder, Inorder, and Postorder traversals of some tree. Write a program to check if they all are of the same tree. Examples: Input: Inorder -&gt; 4 2 5 1 3 Preorder -&gt; 1 2 4 5 3 Postorder -&gt; 4 5 2 3 1Output: YesExplanation: All of the above three traversals are of the same tree 1 / \ 2 3 / \ 4 5Input: Inorder -&gt; 4 2 5 1 3 Preorder
15+ min read
Preorder from Inorder and Postorder traversals
Given Inorder and Postorder traversals of a binary tree, print Preorder traversal. Example: Input: Postorder traversal post[] = {4, 5, 2, 6, 3, 1} Inorder traversal in[] = {4, 2, 5, 1, 3, 6} Output: Preorder traversal 1, 2, 4, 5, 3, 6 Traversals in the above example represents following tree 1 / \ 2 3 / \ \ 4 5 6Recommended: Please solve it on “PRA
15 min read
Preorder, Postorder and Inorder Traversal of a Binary Tree using a single Stack
Given a binary tree, the task is to print all the nodes of the binary tree in Pre-order, Post-order, and In-order iteratively using only one stack traversal. Examples: Input: Output:Preorder Traversal: 1 2 3Inorder Traversal: 2 1 3Postorder Traversal: 2 3 1 Input: Output:Preorder traversal: 1 2 4 5 3 6 7Inorder traversal: 4 2 5 1 6 3 7Post-order tr
13 min read
Construct Full Binary Tree from given preorder and postorder traversals
Given two arrays that represent preorder and postorder traversals of a full binary tree, construct the binary tree. Full Binary Tree is a binary tree where every node has either 0 or 2 children. Illustration: Following are examples of Full Trees. 1 / \ 2 3 / \ / \ 4 5 6 7 1 / \ 2 3 / \ 4 5 / \ 6 7 1 / \ 2 3 / \ / \ 4 5 6 7 / \ 8 9 It is not possibl
14 min read
Find postorder traversal of BST from preorder traversal
Given an array representing preorder traversal of BST, print its postorder traversal. Examples: Input : 40 30 35 80 100 Output : 35 30 100 80 40 Input : 40 30 32 35 80 90 100 120 Output : 35 32 30 120 100 90 80 40 Prerequisite: Construct BST from given preorder traversal Simple Approach: A simple solution is to first construct BST from a given preo
9 min read
Construct Tree from given Inorder and Preorder traversals
Let us consider the below traversals: Inorder sequence: D B E A F C Preorder sequence: A B D E C FRecommended PracticeConstruct Tree from Inorder &amp; PreorderTry It! In a Preorder sequence, the leftmost element is the root of the tree. So we know 'A' is the root for given sequences. By searching ‘A’ in the Inorder sequence, we can find out all el
15+ min read
Check if given inorder and preorder traversals are valid for any Binary Tree without building the tree
cGiven two arrays pre[] and in[] representing the preorder and inorder traversal of the binary tree, the task is to check if the given traversals are valid for any binary tree or not without building the tree. If it is possible, then print Yes. Otherwise, print No. Examples: Input: pre[] = {1, 2, 4, 5, 7, 3, 6, 8}, in[] = {4, 2, 5, 7, 1, 6, 8, 3}Ou
15+ min read
Construct Full Binary Tree using its Preorder traversal and Preorder traversal of its mirror tree
Given two arrays that represent Preorder traversals of a full binary tree and its mirror tree, we need to write a program to construct the binary tree using these two Preorder traversals.A Full Binary Tree is a binary tree where every node has either 0 or 2 children. Note: It is not possible to construct a general binary tree using these two traver
12 min read
Binary Search Tree (BST) Traversals – Inorder, Preorder, Post Order
Given a Binary Search Tree, The task is to print the elements in inorder, preorder, and postorder traversal of the Binary Search Tree. Input: Output: Inorder Traversal: 10 20 30 100 150 200 300Preorder Traversal: 100 20 10 30 200 150 300Postorder Traversal: 10 30 20 150 300 200 100 Input: Output: Inorder Traversal: 8 12 20 22 25 30 40Preorder Trave
11 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg