retagged by
1,552 views

1 Answer

0 votes
0 votes

If you know what inorder is then predecessor / successor is too easy 
e.g  inorder of a BST  is increasing sorted order 
3   5   8   12   15   21   25   27   31   35
if u want to find inorder successor of 15  
u can see it is 21  
Now how to find it in BST   inorder successor of 15
pick up right subtree of 15 and find minimum element there which is 21 
And to minimum element in BST you have to travel to leftmost branch upto leave i.e go left left left upto leave
Overall Conclusion :  1. Pick right subtree
                                2. then go left left left ..... find minimum element in that subtree which is leftmost element


If you understand this predecessor is just reverse of it 
lemme know if you still have problem

Related questions

0 votes
0 votes
3 answers
2
smartmeet asked Feb 8, 2017
6,895 views
If a node in a BST has two children, then its in-order predecessor hasa) No left childb) No right childc) 2 childrend) no child
2 votes
2 votes
1 answer
3
arya_stark asked Jul 4, 2018
7,132 views
Preorder is same as :a) depth-first order b) breadth-first searchc) topological order d) linear order
1 votes
1 votes
0 answers
4
iarnav asked Jan 6, 2018
609 views
WHAT IS THE POST ORDER IF ROOT NODE IS P?