IN-FEED-AD

Find Preorder, Postorder & Inorder of Binary Search Tree(BST) in Data Structure

Find Preorder, Postorder & Inorder of Binary Search Tree(BST) in Data Structure


let's take an example to find preorder, inorder and postorder of given BST


Binary search tree
before finding order we have remember one thing, i.e.
rule for inorder preorder postorder
at every node of tree the left line marker is used to find Preorder, right line marker is used to find Postorder traversal and bottom line marker is used to find Inorder traversal.

Step 1:- we draw these three lines in every nodes of given binary search tree as show below:-

find preorder, inorder , postorder from binary search tree
Step 2:- now we start traversing starting from first node and visit all nodes one by one as show below

find preorder, inorder , postorder from binary search tree



Step 3:- now for finding Preorder we just check only left line marker and write the name of node whose left line marker comes first such as 5--3--2--4 so on.
same as we write the name of nodes whose right line marker comes first such as 2--4--3--6 so on
for Inorder we follow the bottom side marker line as 2--3--4--5-6



  • Preorder:-5,3,2,4,8,6,10
  • Postorder:-2,4,3,6,10,8,5
  • Inorder:-2,3,4,5,6,8,10

Ask question #Pywix

Please Like, Comment, Share and Subscribe THANK YOU!

Post a Comment

0 Comments