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
before finding order we have remember one thing, i.e.
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:-
Step 2:- now we start traversing starting from first node and visit all nodes one by one as show below
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
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
0 Comments
if u have any doubts please let me know,